Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* 32-bit ELF support for ARM |
4e7fd91e | 2 | Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 |
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 "elf/arm.h" |
22 | #include "bfd.h" | |
23 | #include "sysdep.h" | |
24 | #include "libbfd.h" | |
25 | #include "elf-bfd.h" | |
26 | ||
27 | #ifndef NUM_ELEM | |
28 | #define NUM_ELEM(a) (sizeof (a) / (sizeof (a)[0])) | |
29 | #endif | |
30 | ||
7f266840 DJ |
31 | #define elf_info_to_howto 0 |
32 | #define elf_info_to_howto_rel elf32_arm_info_to_howto | |
33 | ||
34 | #define ARM_ELF_ABI_VERSION 0 | |
35 | #define ARM_ELF_OS_ABI_VERSION ELFOSABI_ARM | |
36 | ||
37 | static reloc_howto_type * elf32_arm_reloc_type_lookup | |
38 | PARAMS ((bfd * abfd, bfd_reloc_code_real_type code)); | |
39 | static bfd_boolean elf32_arm_nabi_grok_prstatus | |
40 | PARAMS ((bfd *abfd, Elf_Internal_Note *note)); | |
41 | static bfd_boolean elf32_arm_nabi_grok_psinfo | |
42 | PARAMS ((bfd *abfd, Elf_Internal_Note *note)); | |
43 | ||
44 | /* Note: code such as elf32_arm_reloc_type_lookup expect to use e.g. | |
45 | R_ARM_PC24 as an index into this, and find the R_ARM_PC24 HOWTO | |
46 | in that slot. */ | |
47 | ||
c19d1205 | 48 | static reloc_howto_type elf32_arm_howto_table_1[] = |
7f266840 DJ |
49 | { |
50 | /* No relocation */ | |
51 | HOWTO (R_ARM_NONE, /* type */ | |
52 | 0, /* rightshift */ | |
53 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
54 | 0, /* bitsize */ | |
55 | FALSE, /* pc_relative */ | |
56 | 0, /* bitpos */ | |
57 | complain_overflow_dont,/* complain_on_overflow */ | |
58 | bfd_elf_generic_reloc, /* special_function */ | |
59 | "R_ARM_NONE", /* name */ | |
60 | FALSE, /* partial_inplace */ | |
61 | 0, /* src_mask */ | |
62 | 0, /* dst_mask */ | |
63 | FALSE), /* pcrel_offset */ | |
64 | ||
65 | HOWTO (R_ARM_PC24, /* type */ | |
66 | 2, /* rightshift */ | |
67 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
68 | 24, /* bitsize */ | |
69 | TRUE, /* pc_relative */ | |
70 | 0, /* bitpos */ | |
71 | complain_overflow_signed,/* complain_on_overflow */ | |
72 | bfd_elf_generic_reloc, /* special_function */ | |
73 | "R_ARM_PC24", /* name */ | |
74 | FALSE, /* partial_inplace */ | |
75 | 0x00ffffff, /* src_mask */ | |
76 | 0x00ffffff, /* dst_mask */ | |
77 | TRUE), /* pcrel_offset */ | |
78 | ||
79 | /* 32 bit absolute */ | |
80 | HOWTO (R_ARM_ABS32, /* type */ | |
81 | 0, /* rightshift */ | |
82 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
83 | 32, /* bitsize */ | |
84 | FALSE, /* pc_relative */ | |
85 | 0, /* bitpos */ | |
86 | complain_overflow_bitfield,/* complain_on_overflow */ | |
87 | bfd_elf_generic_reloc, /* special_function */ | |
88 | "R_ARM_ABS32", /* name */ | |
89 | FALSE, /* partial_inplace */ | |
90 | 0xffffffff, /* src_mask */ | |
91 | 0xffffffff, /* dst_mask */ | |
92 | FALSE), /* pcrel_offset */ | |
93 | ||
94 | /* standard 32bit pc-relative reloc */ | |
95 | HOWTO (R_ARM_REL32, /* type */ | |
96 | 0, /* rightshift */ | |
97 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
98 | 32, /* bitsize */ | |
99 | TRUE, /* pc_relative */ | |
100 | 0, /* bitpos */ | |
101 | complain_overflow_bitfield,/* complain_on_overflow */ | |
102 | bfd_elf_generic_reloc, /* special_function */ | |
103 | "R_ARM_REL32", /* name */ | |
104 | FALSE, /* partial_inplace */ | |
105 | 0xffffffff, /* src_mask */ | |
106 | 0xffffffff, /* dst_mask */ | |
107 | TRUE), /* pcrel_offset */ | |
108 | ||
c19d1205 | 109 | /* 8 bit absolute - R_ARM_LDR_PC_G0 in AAELF */ |
7f266840 DJ |
110 | HOWTO (R_ARM_PC13, /* type */ |
111 | 0, /* rightshift */ | |
112 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
113 | 8, /* bitsize */ | |
114 | FALSE, /* pc_relative */ | |
115 | 0, /* bitpos */ | |
116 | complain_overflow_bitfield,/* complain_on_overflow */ | |
117 | bfd_elf_generic_reloc, /* special_function */ | |
118 | "R_ARM_PC13", /* name */ | |
119 | FALSE, /* partial_inplace */ | |
120 | 0x000000ff, /* src_mask */ | |
121 | 0x000000ff, /* dst_mask */ | |
122 | FALSE), /* pcrel_offset */ | |
123 | ||
124 | /* 16 bit absolute */ | |
125 | HOWTO (R_ARM_ABS16, /* type */ | |
126 | 0, /* rightshift */ | |
127 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
128 | 16, /* bitsize */ | |
129 | FALSE, /* pc_relative */ | |
130 | 0, /* bitpos */ | |
131 | complain_overflow_bitfield,/* complain_on_overflow */ | |
132 | bfd_elf_generic_reloc, /* special_function */ | |
133 | "R_ARM_ABS16", /* name */ | |
134 | FALSE, /* partial_inplace */ | |
135 | 0x0000ffff, /* src_mask */ | |
136 | 0x0000ffff, /* dst_mask */ | |
137 | FALSE), /* pcrel_offset */ | |
138 | ||
139 | /* 12 bit absolute */ | |
140 | HOWTO (R_ARM_ABS12, /* type */ | |
141 | 0, /* rightshift */ | |
142 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
143 | 12, /* bitsize */ | |
144 | FALSE, /* pc_relative */ | |
145 | 0, /* bitpos */ | |
146 | complain_overflow_bitfield,/* complain_on_overflow */ | |
147 | bfd_elf_generic_reloc, /* special_function */ | |
148 | "R_ARM_ABS12", /* name */ | |
149 | FALSE, /* partial_inplace */ | |
150 | 0x000008ff, /* src_mask */ | |
151 | 0x000008ff, /* dst_mask */ | |
152 | FALSE), /* pcrel_offset */ | |
153 | ||
154 | HOWTO (R_ARM_THM_ABS5, /* type */ | |
155 | 6, /* rightshift */ | |
156 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
157 | 5, /* bitsize */ | |
158 | FALSE, /* pc_relative */ | |
159 | 0, /* bitpos */ | |
160 | complain_overflow_bitfield,/* complain_on_overflow */ | |
161 | bfd_elf_generic_reloc, /* special_function */ | |
162 | "R_ARM_THM_ABS5", /* name */ | |
163 | FALSE, /* partial_inplace */ | |
164 | 0x000007e0, /* src_mask */ | |
165 | 0x000007e0, /* dst_mask */ | |
166 | FALSE), /* pcrel_offset */ | |
167 | ||
168 | /* 8 bit absolute */ | |
169 | HOWTO (R_ARM_ABS8, /* type */ | |
170 | 0, /* rightshift */ | |
171 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
172 | 8, /* bitsize */ | |
173 | FALSE, /* pc_relative */ | |
174 | 0, /* bitpos */ | |
175 | complain_overflow_bitfield,/* complain_on_overflow */ | |
176 | bfd_elf_generic_reloc, /* special_function */ | |
177 | "R_ARM_ABS8", /* name */ | |
178 | FALSE, /* partial_inplace */ | |
179 | 0x000000ff, /* src_mask */ | |
180 | 0x000000ff, /* dst_mask */ | |
181 | FALSE), /* pcrel_offset */ | |
182 | ||
183 | HOWTO (R_ARM_SBREL32, /* type */ | |
184 | 0, /* rightshift */ | |
185 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
186 | 32, /* bitsize */ | |
187 | FALSE, /* pc_relative */ | |
188 | 0, /* bitpos */ | |
189 | complain_overflow_dont,/* complain_on_overflow */ | |
190 | bfd_elf_generic_reloc, /* special_function */ | |
191 | "R_ARM_SBREL32", /* name */ | |
192 | FALSE, /* partial_inplace */ | |
193 | 0xffffffff, /* src_mask */ | |
194 | 0xffffffff, /* dst_mask */ | |
195 | FALSE), /* pcrel_offset */ | |
196 | ||
c19d1205 ZW |
197 | /* FIXME: Has two more bits of offset in Thumb32. */ |
198 | HOWTO (R_ARM_THM_CALL, /* type */ | |
7f266840 DJ |
199 | 1, /* rightshift */ |
200 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
201 | 23, /* bitsize */ | |
202 | TRUE, /* pc_relative */ | |
203 | 0, /* bitpos */ | |
204 | complain_overflow_signed,/* complain_on_overflow */ | |
205 | bfd_elf_generic_reloc, /* special_function */ | |
c19d1205 | 206 | "R_ARM_THM_CALL", /* name */ |
7f266840 DJ |
207 | FALSE, /* partial_inplace */ |
208 | 0x07ff07ff, /* src_mask */ | |
209 | 0x07ff07ff, /* dst_mask */ | |
210 | TRUE), /* pcrel_offset */ | |
211 | ||
212 | HOWTO (R_ARM_THM_PC8, /* type */ | |
213 | 1, /* rightshift */ | |
214 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
215 | 8, /* bitsize */ | |
216 | TRUE, /* pc_relative */ | |
217 | 0, /* bitpos */ | |
218 | complain_overflow_signed,/* complain_on_overflow */ | |
219 | bfd_elf_generic_reloc, /* special_function */ | |
220 | "R_ARM_THM_PC8", /* name */ | |
221 | FALSE, /* partial_inplace */ | |
222 | 0x000000ff, /* src_mask */ | |
223 | 0x000000ff, /* dst_mask */ | |
224 | TRUE), /* pcrel_offset */ | |
225 | ||
c19d1205 | 226 | HOWTO (R_ARM_BREL_ADJ, /* type */ |
7f266840 DJ |
227 | 1, /* rightshift */ |
228 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
c19d1205 ZW |
229 | 32, /* bitsize */ |
230 | FALSE, /* pc_relative */ | |
7f266840 DJ |
231 | 0, /* bitpos */ |
232 | complain_overflow_signed,/* complain_on_overflow */ | |
233 | bfd_elf_generic_reloc, /* special_function */ | |
c19d1205 | 234 | "R_ARM_BREL_ADJ", /* name */ |
7f266840 | 235 | FALSE, /* partial_inplace */ |
c19d1205 ZW |
236 | 0xffffffff, /* src_mask */ |
237 | 0xffffffff, /* dst_mask */ | |
238 | FALSE), /* pcrel_offset */ | |
7f266840 DJ |
239 | |
240 | HOWTO (R_ARM_SWI24, /* type */ | |
241 | 0, /* rightshift */ | |
242 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
243 | 0, /* bitsize */ | |
244 | FALSE, /* pc_relative */ | |
245 | 0, /* bitpos */ | |
246 | complain_overflow_signed,/* complain_on_overflow */ | |
247 | bfd_elf_generic_reloc, /* special_function */ | |
248 | "R_ARM_SWI24", /* name */ | |
249 | FALSE, /* partial_inplace */ | |
250 | 0x00000000, /* src_mask */ | |
251 | 0x00000000, /* dst_mask */ | |
252 | FALSE), /* pcrel_offset */ | |
253 | ||
254 | HOWTO (R_ARM_THM_SWI8, /* type */ | |
255 | 0, /* rightshift */ | |
256 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
257 | 0, /* bitsize */ | |
258 | FALSE, /* pc_relative */ | |
259 | 0, /* bitpos */ | |
260 | complain_overflow_signed,/* complain_on_overflow */ | |
261 | bfd_elf_generic_reloc, /* special_function */ | |
262 | "R_ARM_SWI8", /* name */ | |
263 | FALSE, /* partial_inplace */ | |
264 | 0x00000000, /* src_mask */ | |
265 | 0x00000000, /* dst_mask */ | |
266 | FALSE), /* pcrel_offset */ | |
267 | ||
268 | /* BLX instruction for the ARM. */ | |
269 | HOWTO (R_ARM_XPC25, /* type */ | |
270 | 2, /* rightshift */ | |
271 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
272 | 25, /* bitsize */ | |
273 | TRUE, /* pc_relative */ | |
274 | 0, /* bitpos */ | |
275 | complain_overflow_signed,/* complain_on_overflow */ | |
276 | bfd_elf_generic_reloc, /* special_function */ | |
277 | "R_ARM_XPC25", /* name */ | |
278 | FALSE, /* partial_inplace */ | |
279 | 0x00ffffff, /* src_mask */ | |
280 | 0x00ffffff, /* dst_mask */ | |
281 | TRUE), /* pcrel_offset */ | |
282 | ||
283 | /* BLX instruction for the Thumb. */ | |
284 | HOWTO (R_ARM_THM_XPC22, /* type */ | |
285 | 2, /* rightshift */ | |
286 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
287 | 22, /* bitsize */ | |
288 | TRUE, /* pc_relative */ | |
289 | 0, /* bitpos */ | |
290 | complain_overflow_signed,/* complain_on_overflow */ | |
291 | bfd_elf_generic_reloc, /* special_function */ | |
292 | "R_ARM_THM_XPC22", /* name */ | |
293 | FALSE, /* partial_inplace */ | |
294 | 0x07ff07ff, /* src_mask */ | |
295 | 0x07ff07ff, /* dst_mask */ | |
296 | TRUE), /* pcrel_offset */ | |
297 | ||
ba93b8ac | 298 | /* Dynamic TLS relocations. */ |
7f266840 | 299 | |
ba93b8ac DJ |
300 | HOWTO (R_ARM_TLS_DTPMOD32, /* type */ |
301 | 0, /* rightshift */ | |
302 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
303 | 32, /* bitsize */ | |
304 | FALSE, /* pc_relative */ | |
305 | 0, /* bitpos */ | |
306 | complain_overflow_bitfield,/* complain_on_overflow */ | |
307 | bfd_elf_generic_reloc, /* special_function */ | |
308 | "R_ARM_TLS_DTPMOD32", /* name */ | |
309 | TRUE, /* partial_inplace */ | |
310 | 0xffffffff, /* src_mask */ | |
311 | 0xffffffff, /* dst_mask */ | |
312 | FALSE), /* pcrel_offset */ | |
7f266840 | 313 | |
ba93b8ac DJ |
314 | HOWTO (R_ARM_TLS_DTPOFF32, /* type */ |
315 | 0, /* rightshift */ | |
316 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
317 | 32, /* bitsize */ | |
318 | FALSE, /* pc_relative */ | |
319 | 0, /* bitpos */ | |
320 | complain_overflow_bitfield,/* complain_on_overflow */ | |
321 | bfd_elf_generic_reloc, /* special_function */ | |
322 | "R_ARM_TLS_DTPOFF32", /* name */ | |
323 | TRUE, /* partial_inplace */ | |
324 | 0xffffffff, /* src_mask */ | |
325 | 0xffffffff, /* dst_mask */ | |
326 | FALSE), /* pcrel_offset */ | |
7f266840 | 327 | |
ba93b8ac DJ |
328 | HOWTO (R_ARM_TLS_TPOFF32, /* type */ |
329 | 0, /* rightshift */ | |
330 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
331 | 32, /* bitsize */ | |
332 | FALSE, /* pc_relative */ | |
333 | 0, /* bitpos */ | |
334 | complain_overflow_bitfield,/* complain_on_overflow */ | |
335 | bfd_elf_generic_reloc, /* special_function */ | |
336 | "R_ARM_TLS_TPOFF32", /* name */ | |
337 | TRUE, /* partial_inplace */ | |
338 | 0xffffffff, /* src_mask */ | |
339 | 0xffffffff, /* dst_mask */ | |
340 | FALSE), /* pcrel_offset */ | |
7f266840 DJ |
341 | |
342 | /* Relocs used in ARM Linux */ | |
343 | ||
344 | HOWTO (R_ARM_COPY, /* type */ | |
345 | 0, /* rightshift */ | |
346 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
347 | 32, /* bitsize */ | |
348 | FALSE, /* pc_relative */ | |
349 | 0, /* bitpos */ | |
350 | complain_overflow_bitfield,/* complain_on_overflow */ | |
351 | bfd_elf_generic_reloc, /* special_function */ | |
352 | "R_ARM_COPY", /* name */ | |
353 | TRUE, /* partial_inplace */ | |
354 | 0xffffffff, /* src_mask */ | |
355 | 0xffffffff, /* dst_mask */ | |
356 | FALSE), /* pcrel_offset */ | |
357 | ||
358 | HOWTO (R_ARM_GLOB_DAT, /* type */ | |
359 | 0, /* rightshift */ | |
360 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
361 | 32, /* bitsize */ | |
362 | FALSE, /* pc_relative */ | |
363 | 0, /* bitpos */ | |
364 | complain_overflow_bitfield,/* complain_on_overflow */ | |
365 | bfd_elf_generic_reloc, /* special_function */ | |
366 | "R_ARM_GLOB_DAT", /* name */ | |
367 | TRUE, /* partial_inplace */ | |
368 | 0xffffffff, /* src_mask */ | |
369 | 0xffffffff, /* dst_mask */ | |
370 | FALSE), /* pcrel_offset */ | |
371 | ||
372 | HOWTO (R_ARM_JUMP_SLOT, /* type */ | |
373 | 0, /* rightshift */ | |
374 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
375 | 32, /* bitsize */ | |
376 | FALSE, /* pc_relative */ | |
377 | 0, /* bitpos */ | |
378 | complain_overflow_bitfield,/* complain_on_overflow */ | |
379 | bfd_elf_generic_reloc, /* special_function */ | |
380 | "R_ARM_JUMP_SLOT", /* name */ | |
381 | TRUE, /* partial_inplace */ | |
382 | 0xffffffff, /* src_mask */ | |
383 | 0xffffffff, /* dst_mask */ | |
384 | FALSE), /* pcrel_offset */ | |
385 | ||
386 | HOWTO (R_ARM_RELATIVE, /* type */ | |
387 | 0, /* rightshift */ | |
388 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
389 | 32, /* bitsize */ | |
390 | FALSE, /* pc_relative */ | |
391 | 0, /* bitpos */ | |
392 | complain_overflow_bitfield,/* complain_on_overflow */ | |
393 | bfd_elf_generic_reloc, /* special_function */ | |
394 | "R_ARM_RELATIVE", /* name */ | |
395 | TRUE, /* partial_inplace */ | |
396 | 0xffffffff, /* src_mask */ | |
397 | 0xffffffff, /* dst_mask */ | |
398 | FALSE), /* pcrel_offset */ | |
399 | ||
c19d1205 | 400 | HOWTO (R_ARM_GOTOFF32, /* type */ |
7f266840 DJ |
401 | 0, /* rightshift */ |
402 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
403 | 32, /* bitsize */ | |
404 | FALSE, /* pc_relative */ | |
405 | 0, /* bitpos */ | |
406 | complain_overflow_bitfield,/* complain_on_overflow */ | |
407 | bfd_elf_generic_reloc, /* special_function */ | |
c19d1205 | 408 | "R_ARM_GOTOFF32", /* name */ |
7f266840 DJ |
409 | TRUE, /* partial_inplace */ |
410 | 0xffffffff, /* src_mask */ | |
411 | 0xffffffff, /* dst_mask */ | |
412 | FALSE), /* pcrel_offset */ | |
413 | ||
414 | HOWTO (R_ARM_GOTPC, /* type */ | |
415 | 0, /* rightshift */ | |
416 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
417 | 32, /* bitsize */ | |
418 | TRUE, /* pc_relative */ | |
419 | 0, /* bitpos */ | |
420 | complain_overflow_bitfield,/* complain_on_overflow */ | |
421 | bfd_elf_generic_reloc, /* special_function */ | |
422 | "R_ARM_GOTPC", /* name */ | |
423 | TRUE, /* partial_inplace */ | |
424 | 0xffffffff, /* src_mask */ | |
425 | 0xffffffff, /* dst_mask */ | |
426 | TRUE), /* pcrel_offset */ | |
427 | ||
428 | HOWTO (R_ARM_GOT32, /* type */ | |
429 | 0, /* rightshift */ | |
430 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
431 | 32, /* bitsize */ | |
432 | FALSE, /* pc_relative */ | |
433 | 0, /* bitpos */ | |
434 | complain_overflow_bitfield,/* complain_on_overflow */ | |
435 | bfd_elf_generic_reloc, /* special_function */ | |
436 | "R_ARM_GOT32", /* name */ | |
437 | TRUE, /* partial_inplace */ | |
438 | 0xffffffff, /* src_mask */ | |
439 | 0xffffffff, /* dst_mask */ | |
440 | FALSE), /* pcrel_offset */ | |
441 | ||
442 | HOWTO (R_ARM_PLT32, /* type */ | |
443 | 2, /* rightshift */ | |
444 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
445 | 26, /* bitsize */ | |
446 | TRUE, /* pc_relative */ | |
447 | 0, /* bitpos */ | |
448 | complain_overflow_bitfield,/* complain_on_overflow */ | |
449 | bfd_elf_generic_reloc, /* special_function */ | |
450 | "R_ARM_PLT32", /* name */ | |
451 | TRUE, /* partial_inplace */ | |
452 | 0x00ffffff, /* src_mask */ | |
453 | 0x00ffffff, /* dst_mask */ | |
454 | TRUE), /* pcrel_offset */ | |
455 | ||
456 | HOWTO (R_ARM_CALL, /* type */ | |
457 | 2, /* rightshift */ | |
458 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
459 | 24, /* bitsize */ | |
460 | TRUE, /* pc_relative */ | |
461 | 0, /* bitpos */ | |
462 | complain_overflow_signed,/* complain_on_overflow */ | |
463 | bfd_elf_generic_reloc, /* special_function */ | |
464 | "R_ARM_CALL", /* name */ | |
465 | FALSE, /* partial_inplace */ | |
466 | 0x00ffffff, /* src_mask */ | |
467 | 0x00ffffff, /* dst_mask */ | |
468 | TRUE), /* pcrel_offset */ | |
469 | ||
470 | HOWTO (R_ARM_JUMP24, /* type */ | |
471 | 2, /* rightshift */ | |
472 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
473 | 24, /* bitsize */ | |
474 | TRUE, /* pc_relative */ | |
475 | 0, /* bitpos */ | |
476 | complain_overflow_signed,/* complain_on_overflow */ | |
477 | bfd_elf_generic_reloc, /* special_function */ | |
478 | "R_ARM_JUMP24", /* name */ | |
479 | FALSE, /* partial_inplace */ | |
480 | 0x00ffffff, /* src_mask */ | |
481 | 0x00ffffff, /* dst_mask */ | |
482 | TRUE), /* pcrel_offset */ | |
483 | ||
c19d1205 ZW |
484 | HOWTO (R_ARM_THM_JUMP24, /* type */ |
485 | 1, /* rightshift */ | |
486 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
487 | 24, /* bitsize */ | |
488 | TRUE, /* pc_relative */ | |
7f266840 | 489 | 0, /* bitpos */ |
c19d1205 | 490 | complain_overflow_signed,/* complain_on_overflow */ |
7f266840 | 491 | bfd_elf_generic_reloc, /* special_function */ |
c19d1205 | 492 | "R_ARM_THM_JUMP24", /* name */ |
7f266840 | 493 | FALSE, /* partial_inplace */ |
c19d1205 ZW |
494 | 0x07ff2fff, /* src_mask */ |
495 | 0x07ff2fff, /* dst_mask */ | |
496 | TRUE), /* pcrel_offset */ | |
7f266840 | 497 | |
c19d1205 | 498 | HOWTO (R_ARM_BASE_ABS, /* type */ |
7f266840 | 499 | 0, /* rightshift */ |
c19d1205 ZW |
500 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
501 | 32, /* bitsize */ | |
7f266840 DJ |
502 | FALSE, /* pc_relative */ |
503 | 0, /* bitpos */ | |
504 | complain_overflow_dont,/* complain_on_overflow */ | |
505 | bfd_elf_generic_reloc, /* special_function */ | |
c19d1205 | 506 | "R_ARM_BASE_ABS", /* name */ |
7f266840 | 507 | FALSE, /* partial_inplace */ |
c19d1205 ZW |
508 | 0xffffffff, /* src_mask */ |
509 | 0xffffffff, /* dst_mask */ | |
7f266840 DJ |
510 | FALSE), /* pcrel_offset */ |
511 | ||
512 | HOWTO (R_ARM_ALU_PCREL7_0, /* type */ | |
513 | 0, /* rightshift */ | |
514 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
515 | 12, /* bitsize */ | |
516 | TRUE, /* pc_relative */ | |
517 | 0, /* bitpos */ | |
518 | complain_overflow_dont,/* complain_on_overflow */ | |
519 | bfd_elf_generic_reloc, /* special_function */ | |
520 | "R_ARM_ALU_PCREL_7_0", /* name */ | |
521 | FALSE, /* partial_inplace */ | |
522 | 0x00000fff, /* src_mask */ | |
523 | 0x00000fff, /* dst_mask */ | |
524 | TRUE), /* pcrel_offset */ | |
525 | ||
526 | HOWTO (R_ARM_ALU_PCREL15_8, /* type */ | |
527 | 0, /* rightshift */ | |
528 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
529 | 12, /* bitsize */ | |
530 | TRUE, /* pc_relative */ | |
531 | 8, /* bitpos */ | |
532 | complain_overflow_dont,/* complain_on_overflow */ | |
533 | bfd_elf_generic_reloc, /* special_function */ | |
534 | "R_ARM_ALU_PCREL_15_8",/* name */ | |
535 | FALSE, /* partial_inplace */ | |
536 | 0x00000fff, /* src_mask */ | |
537 | 0x00000fff, /* dst_mask */ | |
538 | TRUE), /* pcrel_offset */ | |
539 | ||
540 | HOWTO (R_ARM_ALU_PCREL23_15, /* type */ | |
541 | 0, /* rightshift */ | |
542 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
543 | 12, /* bitsize */ | |
544 | TRUE, /* pc_relative */ | |
545 | 16, /* bitpos */ | |
546 | complain_overflow_dont,/* complain_on_overflow */ | |
547 | bfd_elf_generic_reloc, /* special_function */ | |
548 | "R_ARM_ALU_PCREL_23_15",/* name */ | |
549 | FALSE, /* partial_inplace */ | |
550 | 0x00000fff, /* src_mask */ | |
551 | 0x00000fff, /* dst_mask */ | |
552 | TRUE), /* pcrel_offset */ | |
553 | ||
554 | HOWTO (R_ARM_LDR_SBREL_11_0, /* type */ | |
555 | 0, /* rightshift */ | |
556 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
557 | 12, /* bitsize */ | |
558 | FALSE, /* pc_relative */ | |
559 | 0, /* bitpos */ | |
560 | complain_overflow_dont,/* complain_on_overflow */ | |
561 | bfd_elf_generic_reloc, /* special_function */ | |
562 | "R_ARM_LDR_SBREL_11_0",/* name */ | |
563 | FALSE, /* partial_inplace */ | |
564 | 0x00000fff, /* src_mask */ | |
565 | 0x00000fff, /* dst_mask */ | |
566 | FALSE), /* pcrel_offset */ | |
567 | ||
568 | HOWTO (R_ARM_ALU_SBREL_19_12, /* type */ | |
569 | 0, /* rightshift */ | |
570 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
571 | 8, /* bitsize */ | |
572 | FALSE, /* pc_relative */ | |
573 | 12, /* bitpos */ | |
574 | complain_overflow_dont,/* complain_on_overflow */ | |
575 | bfd_elf_generic_reloc, /* special_function */ | |
576 | "R_ARM_ALU_SBREL_19_12",/* name */ | |
577 | FALSE, /* partial_inplace */ | |
578 | 0x000ff000, /* src_mask */ | |
579 | 0x000ff000, /* dst_mask */ | |
580 | FALSE), /* pcrel_offset */ | |
581 | ||
582 | HOWTO (R_ARM_ALU_SBREL_27_20, /* type */ | |
583 | 0, /* rightshift */ | |
584 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
585 | 8, /* bitsize */ | |
586 | FALSE, /* pc_relative */ | |
587 | 20, /* bitpos */ | |
588 | complain_overflow_dont,/* complain_on_overflow */ | |
589 | bfd_elf_generic_reloc, /* special_function */ | |
590 | "R_ARM_ALU_SBREL_27_20",/* name */ | |
591 | FALSE, /* partial_inplace */ | |
592 | 0x0ff00000, /* src_mask */ | |
593 | 0x0ff00000, /* dst_mask */ | |
594 | FALSE), /* pcrel_offset */ | |
595 | ||
596 | HOWTO (R_ARM_TARGET1, /* type */ | |
597 | 0, /* rightshift */ | |
598 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
599 | 32, /* bitsize */ | |
600 | FALSE, /* pc_relative */ | |
601 | 0, /* bitpos */ | |
602 | complain_overflow_dont,/* complain_on_overflow */ | |
603 | bfd_elf_generic_reloc, /* special_function */ | |
604 | "R_ARM_TARGET1", /* name */ | |
605 | FALSE, /* partial_inplace */ | |
606 | 0xffffffff, /* src_mask */ | |
607 | 0xffffffff, /* dst_mask */ | |
608 | FALSE), /* pcrel_offset */ | |
609 | ||
610 | HOWTO (R_ARM_ROSEGREL32, /* type */ | |
611 | 0, /* rightshift */ | |
612 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
613 | 32, /* bitsize */ | |
614 | FALSE, /* pc_relative */ | |
615 | 0, /* bitpos */ | |
616 | complain_overflow_dont,/* complain_on_overflow */ | |
617 | bfd_elf_generic_reloc, /* special_function */ | |
618 | "R_ARM_ROSEGREL32", /* name */ | |
619 | FALSE, /* partial_inplace */ | |
620 | 0xffffffff, /* src_mask */ | |
621 | 0xffffffff, /* dst_mask */ | |
622 | FALSE), /* pcrel_offset */ | |
623 | ||
624 | HOWTO (R_ARM_V4BX, /* type */ | |
625 | 0, /* rightshift */ | |
626 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
627 | 32, /* bitsize */ | |
628 | FALSE, /* pc_relative */ | |
629 | 0, /* bitpos */ | |
630 | complain_overflow_dont,/* complain_on_overflow */ | |
631 | bfd_elf_generic_reloc, /* special_function */ | |
632 | "R_ARM_V4BX", /* name */ | |
633 | FALSE, /* partial_inplace */ | |
634 | 0xffffffff, /* src_mask */ | |
635 | 0xffffffff, /* dst_mask */ | |
636 | FALSE), /* pcrel_offset */ | |
637 | ||
638 | HOWTO (R_ARM_TARGET2, /* type */ | |
639 | 0, /* rightshift */ | |
640 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
641 | 32, /* bitsize */ | |
642 | FALSE, /* pc_relative */ | |
643 | 0, /* bitpos */ | |
644 | complain_overflow_signed,/* complain_on_overflow */ | |
645 | bfd_elf_generic_reloc, /* special_function */ | |
646 | "R_ARM_TARGET2", /* name */ | |
647 | FALSE, /* partial_inplace */ | |
648 | 0xffffffff, /* src_mask */ | |
649 | 0xffffffff, /* dst_mask */ | |
650 | TRUE), /* pcrel_offset */ | |
651 | ||
652 | HOWTO (R_ARM_PREL31, /* type */ | |
653 | 0, /* rightshift */ | |
654 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
655 | 31, /* bitsize */ | |
656 | TRUE, /* pc_relative */ | |
657 | 0, /* bitpos */ | |
658 | complain_overflow_signed,/* complain_on_overflow */ | |
659 | bfd_elf_generic_reloc, /* special_function */ | |
660 | "R_ARM_PREL31", /* name */ | |
661 | FALSE, /* partial_inplace */ | |
662 | 0x7fffffff, /* src_mask */ | |
663 | 0x7fffffff, /* dst_mask */ | |
664 | TRUE), /* pcrel_offset */ | |
c19d1205 ZW |
665 | |
666 | HOWTO (R_ARM_MOVW_ABS_NC, /* type */ | |
667 | 0, /* rightshift */ | |
668 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
669 | 16, /* bitsize */ | |
670 | FALSE, /* pc_relative */ | |
671 | 0, /* bitpos */ | |
672 | complain_overflow_dont,/* complain_on_overflow */ | |
673 | bfd_elf_generic_reloc, /* special_function */ | |
674 | "R_ARM_MOVW_ABS_NC", /* name */ | |
675 | FALSE, /* partial_inplace */ | |
676 | 0x0000ffff, /* src_mask */ | |
677 | 0x0000ffff, /* dst_mask */ | |
678 | FALSE), /* pcrel_offset */ | |
679 | ||
680 | HOWTO (R_ARM_MOVT_ABS, /* type */ | |
681 | 0, /* rightshift */ | |
682 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
683 | 16, /* bitsize */ | |
684 | FALSE, /* pc_relative */ | |
685 | 0, /* bitpos */ | |
686 | complain_overflow_bitfield,/* complain_on_overflow */ | |
687 | bfd_elf_generic_reloc, /* special_function */ | |
688 | "R_ARM_MOVT_ABS", /* name */ | |
689 | FALSE, /* partial_inplace */ | |
690 | 0x0000ffff, /* src_mask */ | |
691 | 0x0000ffff, /* dst_mask */ | |
692 | FALSE), /* pcrel_offset */ | |
693 | ||
694 | HOWTO (R_ARM_MOVW_PREL_NC, /* type */ | |
695 | 0, /* rightshift */ | |
696 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
697 | 16, /* bitsize */ | |
698 | TRUE, /* pc_relative */ | |
699 | 0, /* bitpos */ | |
700 | complain_overflow_dont,/* complain_on_overflow */ | |
701 | bfd_elf_generic_reloc, /* special_function */ | |
702 | "R_ARM_MOVW_PREL_NC", /* name */ | |
703 | FALSE, /* partial_inplace */ | |
704 | 0x0000ffff, /* src_mask */ | |
705 | 0x0000ffff, /* dst_mask */ | |
706 | TRUE), /* pcrel_offset */ | |
707 | ||
708 | HOWTO (R_ARM_MOVT_PREL, /* type */ | |
709 | 0, /* rightshift */ | |
710 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
711 | 16, /* bitsize */ | |
712 | TRUE, /* pc_relative */ | |
713 | 0, /* bitpos */ | |
714 | complain_overflow_bitfield,/* complain_on_overflow */ | |
715 | bfd_elf_generic_reloc, /* special_function */ | |
716 | "R_ARM_MOVT_PREL", /* name */ | |
717 | FALSE, /* partial_inplace */ | |
718 | 0x0000ffff, /* src_mask */ | |
719 | 0x0000ffff, /* dst_mask */ | |
720 | TRUE), /* pcrel_offset */ | |
721 | ||
722 | HOWTO (R_ARM_THM_MOVW_ABS_NC, /* type */ | |
723 | 0, /* rightshift */ | |
724 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
725 | 16, /* bitsize */ | |
726 | FALSE, /* pc_relative */ | |
727 | 0, /* bitpos */ | |
728 | complain_overflow_dont,/* complain_on_overflow */ | |
729 | bfd_elf_generic_reloc, /* special_function */ | |
730 | "R_ARM_THM_MOVW_ABS_NC",/* name */ | |
731 | FALSE, /* partial_inplace */ | |
732 | 0x040f70ff, /* src_mask */ | |
733 | 0x040f70ff, /* dst_mask */ | |
734 | FALSE), /* pcrel_offset */ | |
735 | ||
736 | HOWTO (R_ARM_THM_MOVT_ABS, /* type */ | |
737 | 0, /* rightshift */ | |
738 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
739 | 16, /* bitsize */ | |
740 | FALSE, /* pc_relative */ | |
741 | 0, /* bitpos */ | |
742 | complain_overflow_bitfield,/* complain_on_overflow */ | |
743 | bfd_elf_generic_reloc, /* special_function */ | |
744 | "R_ARM_THM_MOVT_ABS", /* name */ | |
745 | FALSE, /* partial_inplace */ | |
746 | 0x040f70ff, /* src_mask */ | |
747 | 0x040f70ff, /* dst_mask */ | |
748 | FALSE), /* pcrel_offset */ | |
749 | ||
750 | HOWTO (R_ARM_THM_MOVW_PREL_NC,/* type */ | |
751 | 0, /* rightshift */ | |
752 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
753 | 16, /* bitsize */ | |
754 | TRUE, /* pc_relative */ | |
755 | 0, /* bitpos */ | |
756 | complain_overflow_dont,/* complain_on_overflow */ | |
757 | bfd_elf_generic_reloc, /* special_function */ | |
758 | "R_ARM_THM_MOVW_PREL_NC",/* name */ | |
759 | FALSE, /* partial_inplace */ | |
760 | 0x040f70ff, /* src_mask */ | |
761 | 0x040f70ff, /* dst_mask */ | |
762 | TRUE), /* pcrel_offset */ | |
763 | ||
764 | HOWTO (R_ARM_THM_MOVT_PREL, /* type */ | |
765 | 0, /* rightshift */ | |
766 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
767 | 16, /* bitsize */ | |
768 | TRUE, /* pc_relative */ | |
769 | 0, /* bitpos */ | |
770 | complain_overflow_bitfield,/* complain_on_overflow */ | |
771 | bfd_elf_generic_reloc, /* special_function */ | |
772 | "R_ARM_THM_MOVT_PREL", /* name */ | |
773 | FALSE, /* partial_inplace */ | |
774 | 0x040f70ff, /* src_mask */ | |
775 | 0x040f70ff, /* dst_mask */ | |
776 | TRUE), /* pcrel_offset */ | |
777 | ||
778 | HOWTO (R_ARM_THM_JUMP19, /* type */ | |
779 | 1, /* rightshift */ | |
780 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
781 | 19, /* bitsize */ | |
782 | TRUE, /* pc_relative */ | |
783 | 0, /* bitpos */ | |
784 | complain_overflow_signed,/* complain_on_overflow */ | |
785 | bfd_elf_generic_reloc, /* special_function */ | |
786 | "R_ARM_THM_JUMP19", /* name */ | |
787 | FALSE, /* partial_inplace */ | |
788 | 0x043f2fff, /* src_mask */ | |
789 | 0x043f2fff, /* dst_mask */ | |
790 | TRUE), /* pcrel_offset */ | |
791 | ||
792 | HOWTO (R_ARM_THM_JUMP6, /* type */ | |
793 | 1, /* rightshift */ | |
794 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
795 | 6, /* bitsize */ | |
796 | TRUE, /* pc_relative */ | |
797 | 0, /* bitpos */ | |
798 | complain_overflow_unsigned,/* complain_on_overflow */ | |
799 | bfd_elf_generic_reloc, /* special_function */ | |
800 | "R_ARM_THM_JUMP6", /* name */ | |
801 | FALSE, /* partial_inplace */ | |
802 | 0x02f8, /* src_mask */ | |
803 | 0x02f8, /* dst_mask */ | |
804 | TRUE), /* pcrel_offset */ | |
805 | ||
806 | /* These are declared as 13-bit signed relocations because we can | |
807 | address -4095 .. 4095(base) by altering ADDW to SUBW or vice | |
808 | versa. */ | |
809 | HOWTO (R_ARM_THM_ALU_PREL_11_0,/* type */ | |
810 | 0, /* rightshift */ | |
811 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
812 | 13, /* bitsize */ | |
813 | TRUE, /* pc_relative */ | |
814 | 0, /* bitpos */ | |
815 | complain_overflow_signed,/* complain_on_overflow */ | |
816 | bfd_elf_generic_reloc, /* special_function */ | |
817 | "R_ARM_THM_ALU_PREL_11_0",/* name */ | |
818 | FALSE, /* partial_inplace */ | |
819 | 0x040070ff, /* src_mask */ | |
820 | 0x040070ff, /* dst_mask */ | |
821 | TRUE), /* pcrel_offset */ | |
822 | ||
823 | HOWTO (R_ARM_THM_PC12, /* type */ | |
824 | 0, /* rightshift */ | |
825 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
826 | 13, /* bitsize */ | |
827 | TRUE, /* pc_relative */ | |
828 | 0, /* bitpos */ | |
829 | complain_overflow_signed,/* complain_on_overflow */ | |
830 | bfd_elf_generic_reloc, /* special_function */ | |
831 | "R_ARM_THM_PC12", /* name */ | |
832 | FALSE, /* partial_inplace */ | |
833 | 0x040070ff, /* src_mask */ | |
834 | 0x040070ff, /* dst_mask */ | |
835 | TRUE), /* pcrel_offset */ | |
836 | ||
837 | HOWTO (R_ARM_ABS32_NOI, /* type */ | |
838 | 0, /* rightshift */ | |
839 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
840 | 32, /* bitsize */ | |
841 | FALSE, /* pc_relative */ | |
842 | 0, /* bitpos */ | |
843 | complain_overflow_dont,/* complain_on_overflow */ | |
844 | bfd_elf_generic_reloc, /* special_function */ | |
845 | "R_ARM_ABS32_NOI", /* name */ | |
846 | FALSE, /* partial_inplace */ | |
847 | 0xffffffff, /* src_mask */ | |
848 | 0xffffffff, /* dst_mask */ | |
849 | FALSE), /* pcrel_offset */ | |
850 | ||
851 | HOWTO (R_ARM_REL32_NOI, /* type */ | |
852 | 0, /* rightshift */ | |
853 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
854 | 32, /* bitsize */ | |
855 | TRUE, /* pc_relative */ | |
856 | 0, /* bitpos */ | |
857 | complain_overflow_dont,/* complain_on_overflow */ | |
858 | bfd_elf_generic_reloc, /* special_function */ | |
859 | "R_ARM_REL32_NOI", /* name */ | |
860 | FALSE, /* partial_inplace */ | |
861 | 0xffffffff, /* src_mask */ | |
862 | 0xffffffff, /* dst_mask */ | |
863 | FALSE), /* pcrel_offset */ | |
7f266840 DJ |
864 | }; |
865 | ||
c19d1205 ZW |
866 | /* Relocations 57 .. 83 are the "group relocations" which we do not |
867 | support. */ | |
868 | ||
869 | static reloc_howto_type elf32_arm_howto_table_2[] = | |
870 | { | |
871 | HOWTO (R_ARM_MOVW_BREL_NC, /* type */ | |
872 | 0, /* rightshift */ | |
873 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
874 | 16, /* bitsize */ | |
875 | FALSE, /* pc_relative */ | |
876 | 0, /* bitpos */ | |
877 | complain_overflow_dont,/* complain_on_overflow */ | |
878 | bfd_elf_generic_reloc, /* special_function */ | |
879 | "R_ARM_MOVW_BREL_NC", /* name */ | |
880 | FALSE, /* partial_inplace */ | |
881 | 0x0000ffff, /* src_mask */ | |
882 | 0x0000ffff, /* dst_mask */ | |
883 | FALSE), /* pcrel_offset */ | |
884 | ||
885 | HOWTO (R_ARM_MOVT_BREL, /* type */ | |
886 | 0, /* rightshift */ | |
887 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
888 | 16, /* bitsize */ | |
889 | FALSE, /* pc_relative */ | |
890 | 0, /* bitpos */ | |
891 | complain_overflow_bitfield,/* complain_on_overflow */ | |
892 | bfd_elf_generic_reloc, /* special_function */ | |
893 | "R_ARM_MOVT_BREL", /* name */ | |
894 | FALSE, /* partial_inplace */ | |
895 | 0x0000ffff, /* src_mask */ | |
896 | 0x0000ffff, /* dst_mask */ | |
897 | FALSE), /* pcrel_offset */ | |
898 | ||
899 | HOWTO (R_ARM_MOVW_BREL, /* type */ | |
900 | 0, /* rightshift */ | |
901 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
902 | 16, /* bitsize */ | |
903 | FALSE, /* pc_relative */ | |
904 | 0, /* bitpos */ | |
905 | complain_overflow_dont,/* complain_on_overflow */ | |
906 | bfd_elf_generic_reloc, /* special_function */ | |
907 | "R_ARM_MOVW_BREL", /* name */ | |
908 | FALSE, /* partial_inplace */ | |
909 | 0x0000ffff, /* src_mask */ | |
910 | 0x0000ffff, /* dst_mask */ | |
911 | FALSE), /* pcrel_offset */ | |
912 | ||
913 | HOWTO (R_ARM_THM_MOVW_BREL_NC,/* type */ | |
914 | 0, /* rightshift */ | |
915 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
916 | 16, /* bitsize */ | |
917 | FALSE, /* pc_relative */ | |
918 | 0, /* bitpos */ | |
919 | complain_overflow_dont,/* complain_on_overflow */ | |
920 | bfd_elf_generic_reloc, /* special_function */ | |
921 | "R_ARM_THM_MOVW_BREL_NC",/* name */ | |
922 | FALSE, /* partial_inplace */ | |
923 | 0x040f70ff, /* src_mask */ | |
924 | 0x040f70ff, /* dst_mask */ | |
925 | FALSE), /* pcrel_offset */ | |
926 | ||
927 | HOWTO (R_ARM_THM_MOVT_BREL, /* type */ | |
928 | 0, /* rightshift */ | |
929 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
930 | 16, /* bitsize */ | |
931 | FALSE, /* pc_relative */ | |
932 | 0, /* bitpos */ | |
933 | complain_overflow_bitfield,/* complain_on_overflow */ | |
934 | bfd_elf_generic_reloc, /* special_function */ | |
935 | "R_ARM_THM_MOVT_BREL", /* name */ | |
936 | FALSE, /* partial_inplace */ | |
937 | 0x040f70ff, /* src_mask */ | |
938 | 0x040f70ff, /* dst_mask */ | |
939 | FALSE), /* pcrel_offset */ | |
940 | ||
941 | HOWTO (R_ARM_THM_MOVW_BREL, /* type */ | |
942 | 0, /* rightshift */ | |
943 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
944 | 16, /* bitsize */ | |
945 | FALSE, /* pc_relative */ | |
946 | 0, /* bitpos */ | |
947 | complain_overflow_dont,/* complain_on_overflow */ | |
948 | bfd_elf_generic_reloc, /* special_function */ | |
949 | "R_ARM_THM_MOVW_BREL", /* name */ | |
950 | FALSE, /* partial_inplace */ | |
951 | 0x040f70ff, /* src_mask */ | |
952 | 0x040f70ff, /* dst_mask */ | |
953 | FALSE), /* pcrel_offset */ | |
954 | ||
955 | EMPTY_HOWTO (90), /* unallocated */ | |
956 | EMPTY_HOWTO (91), | |
957 | EMPTY_HOWTO (92), | |
958 | EMPTY_HOWTO (93), | |
959 | ||
960 | HOWTO (R_ARM_PLT32_ABS, /* type */ | |
961 | 0, /* rightshift */ | |
962 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
963 | 32, /* bitsize */ | |
964 | FALSE, /* pc_relative */ | |
965 | 0, /* bitpos */ | |
966 | complain_overflow_dont,/* complain_on_overflow */ | |
967 | bfd_elf_generic_reloc, /* special_function */ | |
968 | "R_ARM_PLT32_ABS", /* name */ | |
969 | FALSE, /* partial_inplace */ | |
970 | 0xffffffff, /* src_mask */ | |
971 | 0xffffffff, /* dst_mask */ | |
972 | FALSE), /* pcrel_offset */ | |
973 | ||
974 | HOWTO (R_ARM_GOT_ABS, /* type */ | |
975 | 0, /* rightshift */ | |
976 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
977 | 32, /* bitsize */ | |
978 | FALSE, /* pc_relative */ | |
979 | 0, /* bitpos */ | |
980 | complain_overflow_dont,/* complain_on_overflow */ | |
981 | bfd_elf_generic_reloc, /* special_function */ | |
982 | "R_ARM_GOT_ABS", /* name */ | |
983 | FALSE, /* partial_inplace */ | |
984 | 0xffffffff, /* src_mask */ | |
985 | 0xffffffff, /* dst_mask */ | |
986 | FALSE), /* pcrel_offset */ | |
987 | ||
988 | HOWTO (R_ARM_GOT_PREL, /* type */ | |
989 | 0, /* rightshift */ | |
990 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
991 | 32, /* bitsize */ | |
992 | TRUE, /* pc_relative */ | |
993 | 0, /* bitpos */ | |
994 | complain_overflow_dont, /* complain_on_overflow */ | |
995 | bfd_elf_generic_reloc, /* special_function */ | |
996 | "R_ARM_GOT_PREL", /* name */ | |
997 | FALSE, /* partial_inplace */ | |
998 | 0xffffffff, /* src_mask */ | |
999 | 0xffffffff, /* dst_mask */ | |
1000 | TRUE), /* pcrel_offset */ | |
1001 | ||
1002 | HOWTO (R_ARM_GOT_BREL12, /* type */ | |
1003 | 0, /* rightshift */ | |
1004 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1005 | 12, /* bitsize */ | |
1006 | FALSE, /* pc_relative */ | |
1007 | 0, /* bitpos */ | |
1008 | complain_overflow_bitfield,/* complain_on_overflow */ | |
1009 | bfd_elf_generic_reloc, /* special_function */ | |
1010 | "R_ARM_GOT_BREL12", /* name */ | |
1011 | FALSE, /* partial_inplace */ | |
1012 | 0x00000fff, /* src_mask */ | |
1013 | 0x00000fff, /* dst_mask */ | |
1014 | FALSE), /* pcrel_offset */ | |
1015 | ||
1016 | HOWTO (R_ARM_GOTOFF12, /* type */ | |
1017 | 0, /* rightshift */ | |
1018 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1019 | 12, /* bitsize */ | |
1020 | FALSE, /* pc_relative */ | |
1021 | 0, /* bitpos */ | |
1022 | complain_overflow_bitfield,/* complain_on_overflow */ | |
1023 | bfd_elf_generic_reloc, /* special_function */ | |
1024 | "R_ARM_GOTOFF12", /* name */ | |
1025 | FALSE, /* partial_inplace */ | |
1026 | 0x00000fff, /* src_mask */ | |
1027 | 0x00000fff, /* dst_mask */ | |
1028 | FALSE), /* pcrel_offset */ | |
1029 | ||
1030 | EMPTY_HOWTO (R_ARM_GOTRELAX), /* reserved for future GOT-load optimizations */ | |
1031 | ||
1032 | /* GNU extension to record C++ vtable member usage */ | |
1033 | HOWTO (R_ARM_GNU_VTENTRY, /* type */ | |
ba93b8ac DJ |
1034 | 0, /* rightshift */ |
1035 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
c19d1205 | 1036 | 0, /* bitsize */ |
ba93b8ac DJ |
1037 | FALSE, /* pc_relative */ |
1038 | 0, /* bitpos */ | |
c19d1205 ZW |
1039 | complain_overflow_dont, /* complain_on_overflow */ |
1040 | _bfd_elf_rel_vtable_reloc_fn, /* special_function */ | |
1041 | "R_ARM_GNU_VTENTRY", /* name */ | |
1042 | FALSE, /* partial_inplace */ | |
1043 | 0, /* src_mask */ | |
1044 | 0, /* dst_mask */ | |
1045 | FALSE), /* pcrel_offset */ | |
1046 | ||
1047 | /* GNU extension to record C++ vtable hierarchy */ | |
1048 | HOWTO (R_ARM_GNU_VTINHERIT, /* type */ | |
1049 | 0, /* rightshift */ | |
1050 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1051 | 0, /* bitsize */ | |
1052 | FALSE, /* pc_relative */ | |
1053 | 0, /* bitpos */ | |
1054 | complain_overflow_dont, /* complain_on_overflow */ | |
1055 | NULL, /* special_function */ | |
1056 | "R_ARM_GNU_VTINHERIT", /* name */ | |
1057 | FALSE, /* partial_inplace */ | |
1058 | 0, /* src_mask */ | |
1059 | 0, /* dst_mask */ | |
1060 | FALSE), /* pcrel_offset */ | |
1061 | ||
1062 | HOWTO (R_ARM_THM_JUMP11, /* type */ | |
1063 | 1, /* rightshift */ | |
1064 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1065 | 11, /* bitsize */ | |
1066 | TRUE, /* pc_relative */ | |
1067 | 0, /* bitpos */ | |
1068 | complain_overflow_signed, /* complain_on_overflow */ | |
1069 | bfd_elf_generic_reloc, /* special_function */ | |
1070 | "R_ARM_THM_JUMP11", /* name */ | |
1071 | FALSE, /* partial_inplace */ | |
1072 | 0x000007ff, /* src_mask */ | |
1073 | 0x000007ff, /* dst_mask */ | |
1074 | TRUE), /* pcrel_offset */ | |
1075 | ||
1076 | HOWTO (R_ARM_THM_JUMP8, /* type */ | |
1077 | 1, /* rightshift */ | |
1078 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
1079 | 8, /* bitsize */ | |
1080 | TRUE, /* pc_relative */ | |
1081 | 0, /* bitpos */ | |
1082 | complain_overflow_signed, /* complain_on_overflow */ | |
1083 | bfd_elf_generic_reloc, /* special_function */ | |
1084 | "R_ARM_THM_JUMP8", /* name */ | |
1085 | FALSE, /* partial_inplace */ | |
1086 | 0x000000ff, /* src_mask */ | |
1087 | 0x000000ff, /* dst_mask */ | |
1088 | TRUE), /* pcrel_offset */ | |
ba93b8ac | 1089 | |
c19d1205 ZW |
1090 | /* TLS relocations */ |
1091 | HOWTO (R_ARM_TLS_GD32, /* type */ | |
ba93b8ac DJ |
1092 | 0, /* rightshift */ |
1093 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1094 | 32, /* bitsize */ | |
1095 | FALSE, /* pc_relative */ | |
1096 | 0, /* bitpos */ | |
1097 | complain_overflow_bitfield,/* complain_on_overflow */ | |
c19d1205 ZW |
1098 | NULL, /* special_function */ |
1099 | "R_ARM_TLS_GD32", /* name */ | |
ba93b8ac DJ |
1100 | TRUE, /* partial_inplace */ |
1101 | 0xffffffff, /* src_mask */ | |
1102 | 0xffffffff, /* dst_mask */ | |
c19d1205 | 1103 | FALSE), /* pcrel_offset */ |
ba93b8ac | 1104 | |
ba93b8ac DJ |
1105 | HOWTO (R_ARM_TLS_LDM32, /* type */ |
1106 | 0, /* rightshift */ | |
1107 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1108 | 32, /* bitsize */ | |
1109 | FALSE, /* pc_relative */ | |
1110 | 0, /* bitpos */ | |
1111 | complain_overflow_bitfield,/* complain_on_overflow */ | |
1112 | bfd_elf_generic_reloc, /* special_function */ | |
1113 | "R_ARM_TLS_LDM32", /* name */ | |
1114 | TRUE, /* partial_inplace */ | |
1115 | 0xffffffff, /* src_mask */ | |
1116 | 0xffffffff, /* dst_mask */ | |
c19d1205 | 1117 | FALSE), /* pcrel_offset */ |
ba93b8ac | 1118 | |
c19d1205 | 1119 | HOWTO (R_ARM_TLS_LDO32, /* type */ |
ba93b8ac DJ |
1120 | 0, /* rightshift */ |
1121 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1122 | 32, /* bitsize */ | |
1123 | FALSE, /* pc_relative */ | |
1124 | 0, /* bitpos */ | |
1125 | complain_overflow_bitfield,/* complain_on_overflow */ | |
1126 | bfd_elf_generic_reloc, /* special_function */ | |
c19d1205 | 1127 | "R_ARM_TLS_LDO32", /* name */ |
ba93b8ac DJ |
1128 | TRUE, /* partial_inplace */ |
1129 | 0xffffffff, /* src_mask */ | |
1130 | 0xffffffff, /* dst_mask */ | |
c19d1205 | 1131 | FALSE), /* pcrel_offset */ |
ba93b8ac | 1132 | |
ba93b8ac DJ |
1133 | HOWTO (R_ARM_TLS_IE32, /* type */ |
1134 | 0, /* rightshift */ | |
1135 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1136 | 32, /* bitsize */ | |
1137 | FALSE, /* pc_relative */ | |
1138 | 0, /* bitpos */ | |
1139 | complain_overflow_bitfield,/* complain_on_overflow */ | |
1140 | NULL, /* special_function */ | |
1141 | "R_ARM_TLS_IE32", /* name */ | |
1142 | TRUE, /* partial_inplace */ | |
1143 | 0xffffffff, /* src_mask */ | |
1144 | 0xffffffff, /* dst_mask */ | |
c19d1205 | 1145 | FALSE), /* pcrel_offset */ |
7f266840 | 1146 | |
c19d1205 | 1147 | HOWTO (R_ARM_TLS_LE32, /* type */ |
7f266840 DJ |
1148 | 0, /* rightshift */ |
1149 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
c19d1205 | 1150 | 32, /* bitsize */ |
7f266840 DJ |
1151 | FALSE, /* pc_relative */ |
1152 | 0, /* bitpos */ | |
c19d1205 ZW |
1153 | complain_overflow_bitfield,/* complain_on_overflow */ |
1154 | bfd_elf_generic_reloc, /* special_function */ | |
1155 | "R_ARM_TLS_LE32", /* name */ | |
1156 | TRUE, /* partial_inplace */ | |
1157 | 0xffffffff, /* src_mask */ | |
1158 | 0xffffffff, /* dst_mask */ | |
1159 | FALSE), /* pcrel_offset */ | |
7f266840 | 1160 | |
c19d1205 ZW |
1161 | HOWTO (R_ARM_TLS_LDO12, /* type */ |
1162 | 0, /* rightshift */ | |
1163 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1164 | 12, /* bitsize */ | |
1165 | FALSE, /* pc_relative */ | |
7f266840 | 1166 | 0, /* bitpos */ |
c19d1205 | 1167 | complain_overflow_bitfield,/* complain_on_overflow */ |
7f266840 | 1168 | bfd_elf_generic_reloc, /* special_function */ |
c19d1205 | 1169 | "R_ARM_TLS_LDO12", /* name */ |
7f266840 | 1170 | FALSE, /* partial_inplace */ |
c19d1205 ZW |
1171 | 0x00000fff, /* src_mask */ |
1172 | 0x00000fff, /* dst_mask */ | |
1173 | FALSE), /* pcrel_offset */ | |
7f266840 | 1174 | |
c19d1205 ZW |
1175 | HOWTO (R_ARM_TLS_LE12, /* type */ |
1176 | 0, /* rightshift */ | |
1177 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
1178 | 12, /* bitsize */ | |
1179 | FALSE, /* pc_relative */ | |
7f266840 | 1180 | 0, /* bitpos */ |
c19d1205 | 1181 | complain_overflow_bitfield,/* complain_on_overflow */ |
7f266840 | 1182 | bfd_elf_generic_reloc, /* special_function */ |
c19d1205 | 1183 | "R_ARM_TLS_LE12", /* name */ |
7f266840 | 1184 | FALSE, /* partial_inplace */ |
c19d1205 ZW |
1185 | 0x00000fff, /* src_mask */ |
1186 | 0x00000fff, /* dst_mask */ | |
1187 | FALSE), /* pcrel_offset */ | |
7f266840 | 1188 | |
c19d1205 | 1189 | HOWTO (R_ARM_TLS_IE12GP, /* type */ |
7f266840 DJ |
1190 | 0, /* rightshift */ |
1191 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
c19d1205 ZW |
1192 | 12, /* bitsize */ |
1193 | FALSE, /* pc_relative */ | |
7f266840 | 1194 | 0, /* bitpos */ |
c19d1205 | 1195 | complain_overflow_bitfield,/* complain_on_overflow */ |
7f266840 | 1196 | bfd_elf_generic_reloc, /* special_function */ |
c19d1205 | 1197 | "R_ARM_TLS_IE12GP", /* name */ |
7f266840 | 1198 | FALSE, /* partial_inplace */ |
c19d1205 ZW |
1199 | 0x00000fff, /* src_mask */ |
1200 | 0x00000fff, /* dst_mask */ | |
1201 | FALSE), /* pcrel_offset */ | |
1202 | }; | |
1203 | ||
1204 | /* 112-127 private relocations | |
1205 | 128 R_ARM_ME_TOO, obsolete | |
1206 | 129-255 unallocated in AAELF. | |
7f266840 | 1207 | |
c19d1205 ZW |
1208 | 249-255 extended, currently unused, relocations: */ |
1209 | ||
1210 | static reloc_howto_type elf32_arm_howto_table_3[4] = | |
7f266840 DJ |
1211 | { |
1212 | HOWTO (R_ARM_RREL32, /* type */ | |
1213 | 0, /* rightshift */ | |
1214 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1215 | 0, /* bitsize */ | |
1216 | FALSE, /* pc_relative */ | |
1217 | 0, /* bitpos */ | |
1218 | complain_overflow_dont,/* complain_on_overflow */ | |
1219 | bfd_elf_generic_reloc, /* special_function */ | |
1220 | "R_ARM_RREL32", /* name */ | |
1221 | FALSE, /* partial_inplace */ | |
1222 | 0, /* src_mask */ | |
1223 | 0, /* dst_mask */ | |
1224 | FALSE), /* pcrel_offset */ | |
1225 | ||
1226 | HOWTO (R_ARM_RABS32, /* type */ | |
1227 | 0, /* rightshift */ | |
1228 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1229 | 0, /* bitsize */ | |
1230 | FALSE, /* pc_relative */ | |
1231 | 0, /* bitpos */ | |
1232 | complain_overflow_dont,/* complain_on_overflow */ | |
1233 | bfd_elf_generic_reloc, /* special_function */ | |
1234 | "R_ARM_RABS32", /* name */ | |
1235 | FALSE, /* partial_inplace */ | |
1236 | 0, /* src_mask */ | |
1237 | 0, /* dst_mask */ | |
1238 | FALSE), /* pcrel_offset */ | |
1239 | ||
1240 | HOWTO (R_ARM_RPC24, /* type */ | |
1241 | 0, /* rightshift */ | |
1242 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1243 | 0, /* bitsize */ | |
1244 | FALSE, /* pc_relative */ | |
1245 | 0, /* bitpos */ | |
1246 | complain_overflow_dont,/* complain_on_overflow */ | |
1247 | bfd_elf_generic_reloc, /* special_function */ | |
1248 | "R_ARM_RPC24", /* name */ | |
1249 | FALSE, /* partial_inplace */ | |
1250 | 0, /* src_mask */ | |
1251 | 0, /* dst_mask */ | |
1252 | FALSE), /* pcrel_offset */ | |
1253 | ||
1254 | HOWTO (R_ARM_RBASE, /* type */ | |
1255 | 0, /* rightshift */ | |
1256 | 0, /* size (0 = byte, 1 = short, 2 = long) */ | |
1257 | 0, /* bitsize */ | |
1258 | FALSE, /* pc_relative */ | |
1259 | 0, /* bitpos */ | |
1260 | complain_overflow_dont,/* complain_on_overflow */ | |
1261 | bfd_elf_generic_reloc, /* special_function */ | |
1262 | "R_ARM_RBASE", /* name */ | |
1263 | FALSE, /* partial_inplace */ | |
1264 | 0, /* src_mask */ | |
1265 | 0, /* dst_mask */ | |
1266 | FALSE) /* pcrel_offset */ | |
1267 | }; | |
1268 | ||
1269 | static reloc_howto_type * | |
1270 | elf32_arm_howto_from_type (unsigned int r_type) | |
1271 | { | |
c19d1205 ZW |
1272 | if (r_type < NUM_ELEM (elf32_arm_howto_table_1)) |
1273 | return &elf32_arm_howto_table_1[r_type]; | |
ba93b8ac | 1274 | |
c19d1205 ZW |
1275 | if (r_type >= R_ARM_MOVW_BREL_NC |
1276 | && r_type < R_ARM_MOVW_BREL_NC + NUM_ELEM (elf32_arm_howto_table_2)) | |
1277 | return &elf32_arm_howto_table_2[r_type - R_ARM_MOVW_BREL_NC]; | |
7f266840 | 1278 | |
c19d1205 ZW |
1279 | if (r_type >= R_ARM_RREL32 |
1280 | && r_type < R_ARM_RREL32 + NUM_ELEM (elf32_arm_howto_table_2)) | |
1281 | return &elf32_arm_howto_table_3[r_type - R_ARM_RREL32]; | |
7f266840 | 1282 | |
c19d1205 | 1283 | return NULL; |
7f266840 DJ |
1284 | } |
1285 | ||
1286 | static void | |
1287 | elf32_arm_info_to_howto (bfd * abfd ATTRIBUTE_UNUSED, arelent * bfd_reloc, | |
1288 | Elf_Internal_Rela * elf_reloc) | |
1289 | { | |
1290 | unsigned int r_type; | |
1291 | ||
1292 | r_type = ELF32_R_TYPE (elf_reloc->r_info); | |
1293 | bfd_reloc->howto = elf32_arm_howto_from_type (r_type); | |
1294 | } | |
1295 | ||
1296 | struct elf32_arm_reloc_map | |
1297 | { | |
1298 | bfd_reloc_code_real_type bfd_reloc_val; | |
1299 | unsigned char elf_reloc_val; | |
1300 | }; | |
1301 | ||
1302 | /* All entries in this list must also be present in elf32_arm_howto_table. */ | |
1303 | static const struct elf32_arm_reloc_map elf32_arm_reloc_map[] = | |
1304 | { | |
1305 | {BFD_RELOC_NONE, R_ARM_NONE}, | |
1306 | {BFD_RELOC_ARM_PCREL_BRANCH, R_ARM_PC24}, | |
1307 | {BFD_RELOC_ARM_PCREL_BLX, R_ARM_XPC25}, | |
1308 | {BFD_RELOC_THUMB_PCREL_BLX, R_ARM_THM_XPC22}, | |
1309 | {BFD_RELOC_32, R_ARM_ABS32}, | |
1310 | {BFD_RELOC_32_PCREL, R_ARM_REL32}, | |
1311 | {BFD_RELOC_8, R_ARM_ABS8}, | |
1312 | {BFD_RELOC_16, R_ARM_ABS16}, | |
1313 | {BFD_RELOC_ARM_OFFSET_IMM, R_ARM_ABS12}, | |
1314 | {BFD_RELOC_ARM_THUMB_OFFSET, R_ARM_THM_ABS5}, | |
c19d1205 ZW |
1315 | {BFD_RELOC_THUMB_PCREL_BRANCH25, R_ARM_THM_JUMP24}, |
1316 | {BFD_RELOC_THUMB_PCREL_BRANCH23, R_ARM_THM_CALL}, | |
1317 | {BFD_RELOC_THUMB_PCREL_BRANCH12, R_ARM_THM_JUMP11}, | |
1318 | {BFD_RELOC_THUMB_PCREL_BRANCH20, R_ARM_THM_JUMP19}, | |
1319 | {BFD_RELOC_THUMB_PCREL_BRANCH9, R_ARM_THM_JUMP8}, | |
1320 | {BFD_RELOC_THUMB_PCREL_BRANCH7, R_ARM_THM_JUMP6}, | |
7f266840 DJ |
1321 | {BFD_RELOC_ARM_GLOB_DAT, R_ARM_GLOB_DAT}, |
1322 | {BFD_RELOC_ARM_JUMP_SLOT, R_ARM_JUMP_SLOT}, | |
1323 | {BFD_RELOC_ARM_RELATIVE, R_ARM_RELATIVE}, | |
c19d1205 | 1324 | {BFD_RELOC_ARM_GOTOFF, R_ARM_GOTOFF32}, |
7f266840 DJ |
1325 | {BFD_RELOC_ARM_GOTPC, R_ARM_GOTPC}, |
1326 | {BFD_RELOC_ARM_GOT32, R_ARM_GOT32}, | |
1327 | {BFD_RELOC_ARM_PLT32, R_ARM_PLT32}, | |
1328 | {BFD_RELOC_ARM_TARGET1, R_ARM_TARGET1}, | |
1329 | {BFD_RELOC_ARM_ROSEGREL32, R_ARM_ROSEGREL32}, | |
1330 | {BFD_RELOC_ARM_SBREL32, R_ARM_SBREL32}, | |
1331 | {BFD_RELOC_ARM_PREL31, R_ARM_PREL31}, | |
ba93b8ac DJ |
1332 | {BFD_RELOC_ARM_TARGET2, R_ARM_TARGET2}, |
1333 | {BFD_RELOC_ARM_PLT32, R_ARM_PLT32}, | |
1334 | {BFD_RELOC_ARM_TLS_GD32, R_ARM_TLS_GD32}, | |
1335 | {BFD_RELOC_ARM_TLS_LDO32, R_ARM_TLS_LDO32}, | |
1336 | {BFD_RELOC_ARM_TLS_LDM32, R_ARM_TLS_LDM32}, | |
1337 | {BFD_RELOC_ARM_TLS_DTPMOD32, R_ARM_TLS_DTPMOD32}, | |
1338 | {BFD_RELOC_ARM_TLS_DTPOFF32, R_ARM_TLS_DTPOFF32}, | |
1339 | {BFD_RELOC_ARM_TLS_TPOFF32, R_ARM_TLS_TPOFF32}, | |
1340 | {BFD_RELOC_ARM_TLS_IE32, R_ARM_TLS_IE32}, | |
1341 | {BFD_RELOC_ARM_TLS_LE32, R_ARM_TLS_LE32}, | |
c19d1205 ZW |
1342 | {BFD_RELOC_VTABLE_INHERIT, R_ARM_GNU_VTINHERIT}, |
1343 | {BFD_RELOC_VTABLE_ENTRY, R_ARM_GNU_VTENTRY}, | |
7f266840 DJ |
1344 | }; |
1345 | ||
1346 | static reloc_howto_type * | |
1347 | elf32_arm_reloc_type_lookup (abfd, code) | |
1348 | bfd *abfd ATTRIBUTE_UNUSED; | |
1349 | bfd_reloc_code_real_type code; | |
1350 | { | |
1351 | unsigned int i; | |
c19d1205 ZW |
1352 | for (i = 0; i < NUM_ELEM (elf32_arm_reloc_map); i ++) |
1353 | if (elf32_arm_reloc_map[i].bfd_reloc_val == code) | |
1354 | return elf32_arm_howto_from_type (elf32_arm_reloc_map[i].elf_reloc_val); | |
7f266840 | 1355 | |
c19d1205 | 1356 | return NULL; |
7f266840 DJ |
1357 | } |
1358 | ||
1359 | /* Support for core dump NOTE sections */ | |
1360 | static bfd_boolean | |
1361 | elf32_arm_nabi_grok_prstatus (abfd, note) | |
1362 | bfd *abfd; | |
1363 | Elf_Internal_Note *note; | |
1364 | { | |
1365 | int offset; | |
1366 | size_t size; | |
1367 | ||
1368 | switch (note->descsz) | |
1369 | { | |
1370 | default: | |
1371 | return FALSE; | |
1372 | ||
1373 | case 148: /* Linux/ARM 32-bit*/ | |
1374 | /* pr_cursig */ | |
1375 | elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12); | |
1376 | ||
1377 | /* pr_pid */ | |
1378 | elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24); | |
1379 | ||
1380 | /* pr_reg */ | |
1381 | offset = 72; | |
1382 | size = 72; | |
1383 | ||
1384 | break; | |
1385 | } | |
1386 | ||
1387 | /* Make a ".reg/999" section. */ | |
1388 | return _bfd_elfcore_make_pseudosection (abfd, ".reg", | |
1389 | size, note->descpos + offset); | |
1390 | } | |
1391 | ||
1392 | static bfd_boolean | |
1393 | elf32_arm_nabi_grok_psinfo (abfd, note) | |
1394 | bfd *abfd; | |
1395 | Elf_Internal_Note *note; | |
1396 | { | |
1397 | switch (note->descsz) | |
1398 | { | |
1399 | default: | |
1400 | return FALSE; | |
1401 | ||
1402 | case 124: /* Linux/ARM elf_prpsinfo */ | |
1403 | elf_tdata (abfd)->core_program | |
1404 | = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16); | |
1405 | elf_tdata (abfd)->core_command | |
1406 | = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80); | |
1407 | } | |
1408 | ||
1409 | /* Note that for some reason, a spurious space is tacked | |
1410 | onto the end of the args in some (at least one anyway) | |
1411 | implementations, so strip it off if it exists. */ | |
1412 | ||
1413 | { | |
1414 | char *command = elf_tdata (abfd)->core_command; | |
1415 | int n = strlen (command); | |
1416 | ||
1417 | if (0 < n && command[n - 1] == ' ') | |
1418 | command[n - 1] = '\0'; | |
1419 | } | |
1420 | ||
1421 | return TRUE; | |
1422 | } | |
1423 | ||
1424 | #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vec | |
1425 | #define TARGET_LITTLE_NAME "elf32-littlearm" | |
1426 | #define TARGET_BIG_SYM bfd_elf32_bigarm_vec | |
1427 | #define TARGET_BIG_NAME "elf32-bigarm" | |
1428 | ||
1429 | #define elf_backend_grok_prstatus elf32_arm_nabi_grok_prstatus | |
1430 | #define elf_backend_grok_psinfo elf32_arm_nabi_grok_psinfo | |
1431 | ||
252b5132 RH |
1432 | typedef unsigned long int insn32; |
1433 | typedef unsigned short int insn16; | |
1434 | ||
8cb51566 | 1435 | /* In lieu of proper flags, assume all EABIv4 objects are interworkable. */ |
57e8b36a | 1436 | #define INTERWORK_FLAG(abfd) \ |
8cb51566 | 1437 | (EF_ARM_EABI_VERSION (elf_elfheader (abfd)->e_flags) == EF_ARM_EABI_VER4 \ |
85a84e7a | 1438 | || (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK)) |
9b485d32 | 1439 | |
252b5132 RH |
1440 | /* The linker script knows the section names for placement. |
1441 | The entry_names are used to do simple name mangling on the stubs. | |
1442 | Given a function name, and its type, the stub can be found. The | |
9b485d32 | 1443 | name can be changed. The only requirement is the %s be present. */ |
252b5132 RH |
1444 | #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t" |
1445 | #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb" | |
1446 | ||
1447 | #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7" | |
1448 | #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm" | |
1449 | ||
1450 | /* The name of the dynamic interpreter. This is put in the .interp | |
1451 | section. */ | |
1452 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1" | |
1453 | ||
5e681ec4 PB |
1454 | #ifdef FOUR_WORD_PLT |
1455 | ||
252b5132 RH |
1456 | /* The first entry in a procedure linkage table looks like |
1457 | this. It is set up so that any shared library function that is | |
59f2c4e7 | 1458 | called before the relocation has been set up calls the dynamic |
9b485d32 | 1459 | linker first. */ |
e5a52504 | 1460 | static const bfd_vma elf32_arm_plt0_entry [] = |
5e681ec4 PB |
1461 | { |
1462 | 0xe52de004, /* str lr, [sp, #-4]! */ | |
1463 | 0xe59fe010, /* ldr lr, [pc, #16] */ | |
1464 | 0xe08fe00e, /* add lr, pc, lr */ | |
1465 | 0xe5bef008, /* ldr pc, [lr, #8]! */ | |
1466 | }; | |
1467 | ||
1468 | /* Subsequent entries in a procedure linkage table look like | |
1469 | this. */ | |
e5a52504 | 1470 | static const bfd_vma elf32_arm_plt_entry [] = |
5e681ec4 PB |
1471 | { |
1472 | 0xe28fc600, /* add ip, pc, #NN */ | |
1473 | 0xe28cca00, /* add ip, ip, #NN */ | |
1474 | 0xe5bcf000, /* ldr pc, [ip, #NN]! */ | |
1475 | 0x00000000, /* unused */ | |
1476 | }; | |
1477 | ||
1478 | #else | |
1479 | ||
5e681ec4 PB |
1480 | /* The first entry in a procedure linkage table looks like |
1481 | this. It is set up so that any shared library function that is | |
1482 | called before the relocation has been set up calls the dynamic | |
1483 | linker first. */ | |
e5a52504 | 1484 | static const bfd_vma elf32_arm_plt0_entry [] = |
917583ad | 1485 | { |
5e681ec4 PB |
1486 | 0xe52de004, /* str lr, [sp, #-4]! */ |
1487 | 0xe59fe004, /* ldr lr, [pc, #4] */ | |
1488 | 0xe08fe00e, /* add lr, pc, lr */ | |
1489 | 0xe5bef008, /* ldr pc, [lr, #8]! */ | |
1490 | 0x00000000, /* &GOT[0] - . */ | |
917583ad | 1491 | }; |
252b5132 RH |
1492 | |
1493 | /* Subsequent entries in a procedure linkage table look like | |
1494 | this. */ | |
e5a52504 | 1495 | static const bfd_vma elf32_arm_plt_entry [] = |
5e681ec4 PB |
1496 | { |
1497 | 0xe28fc600, /* add ip, pc, #0xNN00000 */ | |
1498 | 0xe28cca00, /* add ip, ip, #0xNN000 */ | |
1499 | 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */ | |
1500 | }; | |
1501 | ||
1502 | #endif | |
252b5132 | 1503 | |
b7693d02 DJ |
1504 | /* An initial stub used if the PLT entry is referenced from Thumb code. */ |
1505 | #define PLT_THUMB_STUB_SIZE 4 | |
1506 | static const bfd_vma elf32_arm_plt_thumb_stub [] = | |
1507 | { | |
1508 | 0x4778, /* bx pc */ | |
1509 | 0x46c0 /* nop */ | |
1510 | }; | |
1511 | ||
e5a52504 MM |
1512 | /* The entries in a PLT when using a DLL-based target with multiple |
1513 | address spaces. */ | |
1514 | static const bfd_vma elf32_arm_symbian_plt_entry [] = | |
1515 | { | |
83a358aa | 1516 | 0xe51ff004, /* ldr pc, [pc, #-4] */ |
e5a52504 MM |
1517 | 0x00000000, /* dcd R_ARM_GLOB_DAT(X) */ |
1518 | }; | |
1519 | ||
e489d0ae PB |
1520 | /* Used to build a map of a section. This is required for mixed-endian |
1521 | code/data. */ | |
1522 | ||
1523 | typedef struct elf32_elf_section_map | |
1524 | { | |
1525 | bfd_vma vma; | |
1526 | char type; | |
1527 | } | |
1528 | elf32_arm_section_map; | |
1529 | ||
1530 | struct _arm_elf_section_data | |
1531 | { | |
1532 | struct bfd_elf_section_data elf; | |
1533 | int mapcount; | |
1534 | elf32_arm_section_map *map; | |
1535 | }; | |
1536 | ||
1537 | #define elf32_arm_section_data(sec) \ | |
1538 | ((struct _arm_elf_section_data *) elf_section_data (sec)) | |
1539 | ||
ba93b8ac DJ |
1540 | /* The size of the thread control block. */ |
1541 | #define TCB_SIZE 8 | |
1542 | ||
1543 | struct elf32_arm_obj_tdata | |
1544 | { | |
1545 | struct elf_obj_tdata root; | |
1546 | ||
1547 | /* tls_type for each local got entry. */ | |
1548 | char *local_got_tls_type; | |
1549 | }; | |
1550 | ||
1551 | #define elf32_arm_tdata(abfd) \ | |
1552 | ((struct elf32_arm_obj_tdata *) (abfd)->tdata.any) | |
1553 | ||
1554 | #define elf32_arm_local_got_tls_type(abfd) \ | |
1555 | (elf32_arm_tdata (abfd)->local_got_tls_type) | |
1556 | ||
1557 | static bfd_boolean | |
1558 | elf32_arm_mkobject (bfd *abfd) | |
1559 | { | |
1560 | bfd_size_type amt = sizeof (struct elf32_arm_obj_tdata); | |
1561 | abfd->tdata.any = bfd_zalloc (abfd, amt); | |
1562 | if (abfd->tdata.any == NULL) | |
1563 | return FALSE; | |
1564 | return TRUE; | |
1565 | } | |
1566 | ||
252b5132 RH |
1567 | /* The ARM linker needs to keep track of the number of relocs that it |
1568 | decides to copy in check_relocs for each symbol. This is so that | |
1569 | it can discard PC relative relocs if it doesn't need them when | |
1570 | linking with -Bsymbolic. We store the information in a field | |
1571 | extending the regular ELF linker hash table. */ | |
1572 | ||
ba93b8ac DJ |
1573 | /* This structure keeps track of the number of relocs we have copied |
1574 | for a given symbol. */ | |
5e681ec4 | 1575 | struct elf32_arm_relocs_copied |
917583ad NC |
1576 | { |
1577 | /* Next section. */ | |
5e681ec4 | 1578 | struct elf32_arm_relocs_copied * next; |
917583ad NC |
1579 | /* A section in dynobj. */ |
1580 | asection * section; | |
1581 | /* Number of relocs copied in this section. */ | |
1582 | bfd_size_type count; | |
ba93b8ac DJ |
1583 | /* Number of PC-relative relocs copied in this section. */ |
1584 | bfd_size_type pc_count; | |
917583ad | 1585 | }; |
252b5132 | 1586 | |
ba93b8ac DJ |
1587 | #define elf32_arm_hash_entry(ent) ((struct elf32_arm_link_hash_entry *)(ent)) |
1588 | ||
ba96a88f | 1589 | /* Arm ELF linker hash entry. */ |
252b5132 | 1590 | struct elf32_arm_link_hash_entry |
917583ad NC |
1591 | { |
1592 | struct elf_link_hash_entry root; | |
252b5132 | 1593 | |
917583ad | 1594 | /* Number of PC relative relocs copied for this symbol. */ |
5e681ec4 | 1595 | struct elf32_arm_relocs_copied * relocs_copied; |
b7693d02 DJ |
1596 | |
1597 | /* We reference count Thumb references to a PLT entry separately, | |
1598 | so that we can emit the Thumb trampoline only if needed. */ | |
1599 | bfd_signed_vma plt_thumb_refcount; | |
1600 | ||
1601 | /* Since PLT entries have variable size if the Thumb prologue is | |
1602 | used, we need to record the index into .got.plt instead of | |
1603 | recomputing it from the PLT offset. */ | |
1604 | bfd_signed_vma plt_got_offset; | |
ba93b8ac DJ |
1605 | |
1606 | #define GOT_UNKNOWN 0 | |
1607 | #define GOT_NORMAL 1 | |
1608 | #define GOT_TLS_GD 2 | |
1609 | #define GOT_TLS_IE 4 | |
1610 | unsigned char tls_type; | |
917583ad | 1611 | }; |
252b5132 | 1612 | |
252b5132 | 1613 | /* Traverse an arm ELF linker hash table. */ |
252b5132 RH |
1614 | #define elf32_arm_link_hash_traverse(table, func, info) \ |
1615 | (elf_link_hash_traverse \ | |
1616 | (&(table)->root, \ | |
b7693d02 | 1617 | (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \ |
252b5132 RH |
1618 | (info))) |
1619 | ||
1620 | /* Get the ARM elf linker hash table from a link_info structure. */ | |
1621 | #define elf32_arm_hash_table(info) \ | |
1622 | ((struct elf32_arm_link_hash_table *) ((info)->hash)) | |
1623 | ||
9b485d32 | 1624 | /* ARM ELF linker hash table. */ |
252b5132 | 1625 | struct elf32_arm_link_hash_table |
917583ad NC |
1626 | { |
1627 | /* The main hash table. */ | |
1628 | struct elf_link_hash_table root; | |
252b5132 | 1629 | |
4cc11e76 | 1630 | /* The size in bytes of the section containing the Thumb-to-ARM glue. */ |
dc810e39 | 1631 | bfd_size_type thumb_glue_size; |
252b5132 | 1632 | |
4cc11e76 | 1633 | /* The size in bytes of the section containing the ARM-to-Thumb glue. */ |
dc810e39 | 1634 | bfd_size_type arm_glue_size; |
252b5132 | 1635 | |
4cc11e76 | 1636 | /* An arbitrary input BFD chosen to hold the glue sections. */ |
917583ad | 1637 | bfd * bfd_of_glue_owner; |
ba96a88f | 1638 | |
e489d0ae PB |
1639 | /* Nonzero to output a BE8 image. */ |
1640 | int byteswap_code; | |
1641 | ||
9c504268 PB |
1642 | /* Zero if R_ARM_TARGET1 means R_ARM_ABS32. |
1643 | Nonzero if R_ARM_TARGET1 means R_ARM_ABS32. */ | |
1644 | int target1_is_rel; | |
1645 | ||
eb043451 PB |
1646 | /* The relocation to use for R_ARM_TARGET2 relocations. */ |
1647 | int target2_reloc; | |
1648 | ||
319850b4 JB |
1649 | /* Nonzero to fix BX instructions for ARMv4 targets. */ |
1650 | int fix_v4bx; | |
1651 | ||
33bfe774 JB |
1652 | /* Nonzero if the ARM/Thumb BLX instructions are available for use. */ |
1653 | int use_blx; | |
1654 | ||
e5a52504 MM |
1655 | /* The number of bytes in the initial entry in the PLT. */ |
1656 | bfd_size_type plt_header_size; | |
1657 | ||
1658 | /* The number of bytes in the subsequent PLT etries. */ | |
1659 | bfd_size_type plt_entry_size; | |
1660 | ||
1661 | /* True if the target system is Symbian OS. */ | |
1662 | int symbian_p; | |
1663 | ||
4e7fd91e PB |
1664 | /* True if the target uses REL relocations. */ |
1665 | int use_rel; | |
1666 | ||
5e681ec4 PB |
1667 | /* Short-cuts to get to dynamic linker sections. */ |
1668 | asection *sgot; | |
1669 | asection *sgotplt; | |
1670 | asection *srelgot; | |
1671 | asection *splt; | |
1672 | asection *srelplt; | |
1673 | asection *sdynbss; | |
1674 | asection *srelbss; | |
1675 | ||
ba93b8ac DJ |
1676 | /* Data for R_ARM_TLS_LDM32 relocations. */ |
1677 | union { | |
1678 | bfd_signed_vma refcount; | |
1679 | bfd_vma offset; | |
1680 | } tls_ldm_got; | |
1681 | ||
5e681ec4 PB |
1682 | /* Small local sym to section mapping cache. */ |
1683 | struct sym_sec_cache sym_sec; | |
b7693d02 DJ |
1684 | |
1685 | /* For convenience in allocate_dynrelocs. */ | |
1686 | bfd * obfd; | |
917583ad | 1687 | }; |
252b5132 | 1688 | |
780a67af NC |
1689 | /* Create an entry in an ARM ELF linker hash table. */ |
1690 | ||
1691 | static struct bfd_hash_entry * | |
57e8b36a NC |
1692 | elf32_arm_link_hash_newfunc (struct bfd_hash_entry * entry, |
1693 | struct bfd_hash_table * table, | |
1694 | const char * string) | |
780a67af NC |
1695 | { |
1696 | struct elf32_arm_link_hash_entry * ret = | |
1697 | (struct elf32_arm_link_hash_entry *) entry; | |
1698 | ||
1699 | /* Allocate the structure if it has not already been allocated by a | |
1700 | subclass. */ | |
1701 | if (ret == (struct elf32_arm_link_hash_entry *) NULL) | |
57e8b36a NC |
1702 | ret = bfd_hash_allocate (table, sizeof (struct elf32_arm_link_hash_entry)); |
1703 | if (ret == NULL) | |
780a67af NC |
1704 | return (struct bfd_hash_entry *) ret; |
1705 | ||
1706 | /* Call the allocation method of the superclass. */ | |
1707 | ret = ((struct elf32_arm_link_hash_entry *) | |
1708 | _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret, | |
1709 | table, string)); | |
57e8b36a | 1710 | if (ret != NULL) |
b7693d02 DJ |
1711 | { |
1712 | ret->relocs_copied = NULL; | |
ba93b8ac | 1713 | ret->tls_type = GOT_UNKNOWN; |
b7693d02 DJ |
1714 | ret->plt_thumb_refcount = 0; |
1715 | ret->plt_got_offset = -1; | |
1716 | } | |
780a67af NC |
1717 | |
1718 | return (struct bfd_hash_entry *) ret; | |
1719 | } | |
1720 | ||
5e681ec4 PB |
1721 | /* Create .got, .gotplt, and .rel.got sections in DYNOBJ, and set up |
1722 | shortcuts to them in our hash table. */ | |
1723 | ||
1724 | static bfd_boolean | |
57e8b36a | 1725 | create_got_section (bfd *dynobj, struct bfd_link_info *info) |
5e681ec4 PB |
1726 | { |
1727 | struct elf32_arm_link_hash_table *htab; | |
1728 | ||
e5a52504 MM |
1729 | htab = elf32_arm_hash_table (info); |
1730 | /* BPABI objects never have a GOT, or associated sections. */ | |
1731 | if (htab->symbian_p) | |
1732 | return TRUE; | |
1733 | ||
5e681ec4 PB |
1734 | if (! _bfd_elf_create_got_section (dynobj, info)) |
1735 | return FALSE; | |
1736 | ||
5e681ec4 PB |
1737 | htab->sgot = bfd_get_section_by_name (dynobj, ".got"); |
1738 | htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt"); | |
1739 | if (!htab->sgot || !htab->sgotplt) | |
1740 | abort (); | |
1741 | ||
3496cb2a L |
1742 | htab->srelgot = bfd_make_section_with_flags (dynobj, ".rel.got", |
1743 | (SEC_ALLOC | SEC_LOAD | |
1744 | | SEC_HAS_CONTENTS | |
1745 | | SEC_IN_MEMORY | |
1746 | | SEC_LINKER_CREATED | |
1747 | | SEC_READONLY)); | |
5e681ec4 | 1748 | if (htab->srelgot == NULL |
5e681ec4 PB |
1749 | || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2)) |
1750 | return FALSE; | |
1751 | return TRUE; | |
1752 | } | |
1753 | ||
1754 | /* Create .plt, .rel.plt, .got, .got.plt, .rel.got, .dynbss, and | |
1755 | .rel.bss sections in DYNOBJ, and set up shortcuts to them in our | |
1756 | hash table. */ | |
1757 | ||
1758 | static bfd_boolean | |
57e8b36a | 1759 | elf32_arm_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info) |
5e681ec4 PB |
1760 | { |
1761 | struct elf32_arm_link_hash_table *htab; | |
1762 | ||
1763 | htab = elf32_arm_hash_table (info); | |
1764 | if (!htab->sgot && !create_got_section (dynobj, info)) | |
1765 | return FALSE; | |
1766 | ||
1767 | if (!_bfd_elf_create_dynamic_sections (dynobj, info)) | |
1768 | return FALSE; | |
1769 | ||
1770 | htab->splt = bfd_get_section_by_name (dynobj, ".plt"); | |
1771 | htab->srelplt = bfd_get_section_by_name (dynobj, ".rel.plt"); | |
1772 | htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss"); | |
1773 | if (!info->shared) | |
1774 | htab->srelbss = bfd_get_section_by_name (dynobj, ".rel.bss"); | |
1775 | ||
e5a52504 MM |
1776 | if (!htab->splt |
1777 | || !htab->srelplt | |
1778 | || !htab->sdynbss | |
5e681ec4 PB |
1779 | || (!info->shared && !htab->srelbss)) |
1780 | abort (); | |
1781 | ||
1782 | return TRUE; | |
1783 | } | |
1784 | ||
1785 | /* Copy the extra info we tack onto an elf_link_hash_entry. */ | |
1786 | ||
1787 | static void | |
1788 | elf32_arm_copy_indirect_symbol (const struct elf_backend_data *bed, | |
1789 | struct elf_link_hash_entry *dir, | |
1790 | struct elf_link_hash_entry *ind) | |
1791 | { | |
1792 | struct elf32_arm_link_hash_entry *edir, *eind; | |
1793 | ||
1794 | edir = (struct elf32_arm_link_hash_entry *) dir; | |
1795 | eind = (struct elf32_arm_link_hash_entry *) ind; | |
1796 | ||
1797 | if (eind->relocs_copied != NULL) | |
1798 | { | |
1799 | if (edir->relocs_copied != NULL) | |
1800 | { | |
1801 | struct elf32_arm_relocs_copied **pp; | |
1802 | struct elf32_arm_relocs_copied *p; | |
1803 | ||
1804 | if (ind->root.type == bfd_link_hash_indirect) | |
1805 | abort (); | |
1806 | ||
1807 | /* Add reloc counts against the weak sym to the strong sym | |
1808 | list. Merge any entries against the same section. */ | |
1809 | for (pp = &eind->relocs_copied; (p = *pp) != NULL; ) | |
1810 | { | |
1811 | struct elf32_arm_relocs_copied *q; | |
1812 | ||
1813 | for (q = edir->relocs_copied; q != NULL; q = q->next) | |
1814 | if (q->section == p->section) | |
1815 | { | |
ba93b8ac | 1816 | q->pc_count += p->pc_count; |
5e681ec4 PB |
1817 | q->count += p->count; |
1818 | *pp = p->next; | |
1819 | break; | |
1820 | } | |
1821 | if (q == NULL) | |
1822 | pp = &p->next; | |
1823 | } | |
1824 | *pp = edir->relocs_copied; | |
1825 | } | |
1826 | ||
1827 | edir->relocs_copied = eind->relocs_copied; | |
1828 | eind->relocs_copied = NULL; | |
1829 | } | |
1830 | ||
b7693d02 DJ |
1831 | /* If the direct symbol already has an associated PLT entry, the |
1832 | indirect symbol should not. If it doesn't, swap refcount information | |
1833 | from the indirect symbol. */ | |
1834 | if (edir->plt_thumb_refcount == 0) | |
1835 | { | |
1836 | edir->plt_thumb_refcount = eind->plt_thumb_refcount; | |
1837 | eind->plt_thumb_refcount = 0; | |
1838 | } | |
1839 | else | |
1840 | BFD_ASSERT (eind->plt_thumb_refcount == 0); | |
1841 | ||
ba93b8ac DJ |
1842 | if (ind->root.type == bfd_link_hash_indirect |
1843 | && dir->got.refcount <= 0) | |
1844 | { | |
1845 | edir->tls_type = eind->tls_type; | |
1846 | eind->tls_type = GOT_UNKNOWN; | |
1847 | } | |
1848 | ||
5e681ec4 PB |
1849 | _bfd_elf_link_hash_copy_indirect (bed, dir, ind); |
1850 | } | |
1851 | ||
9b485d32 | 1852 | /* Create an ARM elf linker hash table. */ |
252b5132 RH |
1853 | |
1854 | static struct bfd_link_hash_table * | |
57e8b36a | 1855 | elf32_arm_link_hash_table_create (bfd *abfd) |
252b5132 RH |
1856 | { |
1857 | struct elf32_arm_link_hash_table *ret; | |
dc810e39 | 1858 | bfd_size_type amt = sizeof (struct elf32_arm_link_hash_table); |
252b5132 | 1859 | |
57e8b36a NC |
1860 | ret = bfd_malloc (amt); |
1861 | if (ret == NULL) | |
252b5132 RH |
1862 | return NULL; |
1863 | ||
57e8b36a | 1864 | if (!_bfd_elf_link_hash_table_init (& ret->root, abfd, |
780a67af | 1865 | elf32_arm_link_hash_newfunc)) |
252b5132 | 1866 | { |
e2d34d7d | 1867 | free (ret); |
252b5132 RH |
1868 | return NULL; |
1869 | } | |
1870 | ||
5e681ec4 PB |
1871 | ret->sgot = NULL; |
1872 | ret->sgotplt = NULL; | |
1873 | ret->srelgot = NULL; | |
1874 | ret->splt = NULL; | |
1875 | ret->srelplt = NULL; | |
1876 | ret->sdynbss = NULL; | |
1877 | ret->srelbss = NULL; | |
252b5132 RH |
1878 | ret->thumb_glue_size = 0; |
1879 | ret->arm_glue_size = 0; | |
1880 | ret->bfd_of_glue_owner = NULL; | |
e489d0ae | 1881 | ret->byteswap_code = 0; |
9c504268 | 1882 | ret->target1_is_rel = 0; |
eb043451 | 1883 | ret->target2_reloc = R_ARM_NONE; |
e5a52504 MM |
1884 | #ifdef FOUR_WORD_PLT |
1885 | ret->plt_header_size = 16; | |
1886 | ret->plt_entry_size = 16; | |
1887 | #else | |
1888 | ret->plt_header_size = 20; | |
1889 | ret->plt_entry_size = 12; | |
1890 | #endif | |
33bfe774 JB |
1891 | ret->fix_v4bx = 0; |
1892 | ret->use_blx = 0; | |
e5a52504 | 1893 | ret->symbian_p = 0; |
4e7fd91e | 1894 | ret->use_rel = 1; |
5e681ec4 | 1895 | ret->sym_sec.abfd = NULL; |
b7693d02 | 1896 | ret->obfd = abfd; |
ba93b8ac | 1897 | ret->tls_ldm_got.refcount = 0; |
252b5132 RH |
1898 | |
1899 | return &ret->root.root; | |
1900 | } | |
1901 | ||
9b485d32 NC |
1902 | /* Locate the Thumb encoded calling stub for NAME. */ |
1903 | ||
252b5132 | 1904 | static struct elf_link_hash_entry * |
57e8b36a NC |
1905 | find_thumb_glue (struct bfd_link_info *link_info, |
1906 | const char *name, | |
1907 | bfd *input_bfd) | |
252b5132 RH |
1908 | { |
1909 | char *tmp_name; | |
1910 | struct elf_link_hash_entry *hash; | |
1911 | struct elf32_arm_link_hash_table *hash_table; | |
1912 | ||
1913 | /* We need a pointer to the armelf specific hash table. */ | |
1914 | hash_table = elf32_arm_hash_table (link_info); | |
1915 | ||
57e8b36a NC |
1916 | tmp_name = bfd_malloc ((bfd_size_type) strlen (name) |
1917 | + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1); | |
252b5132 RH |
1918 | |
1919 | BFD_ASSERT (tmp_name); | |
1920 | ||
1921 | sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name); | |
1922 | ||
1923 | hash = elf_link_hash_lookup | |
b34976b6 | 1924 | (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE); |
252b5132 RH |
1925 | |
1926 | if (hash == NULL) | |
1927 | /* xgettext:c-format */ | |
d003868e AM |
1928 | (*_bfd_error_handler) (_("%B: unable to find THUMB glue '%s' for `%s'"), |
1929 | input_bfd, tmp_name, name); | |
252b5132 RH |
1930 | |
1931 | free (tmp_name); | |
1932 | ||
1933 | return hash; | |
1934 | } | |
1935 | ||
9b485d32 NC |
1936 | /* Locate the ARM encoded calling stub for NAME. */ |
1937 | ||
252b5132 | 1938 | static struct elf_link_hash_entry * |
57e8b36a NC |
1939 | find_arm_glue (struct bfd_link_info *link_info, |
1940 | const char *name, | |
1941 | bfd *input_bfd) | |
252b5132 RH |
1942 | { |
1943 | char *tmp_name; | |
1944 | struct elf_link_hash_entry *myh; | |
1945 | struct elf32_arm_link_hash_table *hash_table; | |
1946 | ||
1947 | /* We need a pointer to the elfarm specific hash table. */ | |
1948 | hash_table = elf32_arm_hash_table (link_info); | |
1949 | ||
57e8b36a NC |
1950 | tmp_name = bfd_malloc ((bfd_size_type) strlen (name) |
1951 | + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1); | |
252b5132 RH |
1952 | |
1953 | BFD_ASSERT (tmp_name); | |
1954 | ||
1955 | sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name); | |
1956 | ||
1957 | myh = elf_link_hash_lookup | |
b34976b6 | 1958 | (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE); |
252b5132 RH |
1959 | |
1960 | if (myh == NULL) | |
1961 | /* xgettext:c-format */ | |
d003868e AM |
1962 | (*_bfd_error_handler) (_("%B: unable to find ARM glue '%s' for `%s'"), |
1963 | input_bfd, tmp_name, name); | |
252b5132 RH |
1964 | |
1965 | free (tmp_name); | |
1966 | ||
1967 | return myh; | |
1968 | } | |
1969 | ||
8f6277f5 | 1970 | /* ARM->Thumb glue (static images): |
252b5132 RH |
1971 | |
1972 | .arm | |
1973 | __func_from_arm: | |
1974 | ldr r12, __func_addr | |
1975 | bx r12 | |
1976 | __func_addr: | |
8f6277f5 | 1977 | .word func @ behave as if you saw a ARM_32 reloc. |
252b5132 | 1978 | |
8f6277f5 PB |
1979 | (relocatable images) |
1980 | .arm | |
1981 | __func_from_arm: | |
1982 | ldr r12, __func_offset | |
1983 | add r12, r12, pc | |
1984 | bx r12 | |
1985 | __func_offset: | |
1986 | .word func - . | |
1987 | */ | |
1988 | ||
1989 | #define ARM2THUMB_STATIC_GLUE_SIZE 12 | |
252b5132 RH |
1990 | static const insn32 a2t1_ldr_insn = 0xe59fc000; |
1991 | static const insn32 a2t2_bx_r12_insn = 0xe12fff1c; | |
1992 | static const insn32 a2t3_func_addr_insn = 0x00000001; | |
1993 | ||
8f6277f5 PB |
1994 | #define ARM2THUMB_PIC_GLUE_SIZE 16 |
1995 | static const insn32 a2t1p_ldr_insn = 0xe59fc004; | |
1996 | static const insn32 a2t2p_add_pc_insn = 0xe08cc00f; | |
1997 | static const insn32 a2t3p_bx_r12_insn = 0xe12fff1c; | |
1998 | ||
9b485d32 | 1999 | /* Thumb->ARM: Thumb->(non-interworking aware) ARM |
252b5132 RH |
2000 | |
2001 | .thumb .thumb | |
2002 | .align 2 .align 2 | |
2003 | __func_from_thumb: __func_from_thumb: | |
2004 | bx pc push {r6, lr} | |
2005 | nop ldr r6, __func_addr | |
2006 | .arm mov lr, pc | |
2007 | __func_change_to_arm: bx r6 | |
2008 | b func .arm | |
2009 | __func_back_to_thumb: | |
2010 | ldmia r13! {r6, lr} | |
2011 | bx lr | |
2012 | __func_addr: | |
9b485d32 | 2013 | .word func */ |
252b5132 RH |
2014 | |
2015 | #define THUMB2ARM_GLUE_SIZE 8 | |
2016 | static const insn16 t2a1_bx_pc_insn = 0x4778; | |
2017 | static const insn16 t2a2_noop_insn = 0x46c0; | |
2018 | static const insn32 t2a3_b_insn = 0xea000000; | |
2019 | ||
7e392df6 | 2020 | #ifndef ELFARM_NABI_C_INCLUDED |
b34976b6 | 2021 | bfd_boolean |
57e8b36a | 2022 | bfd_elf32_arm_allocate_interworking_sections (struct bfd_link_info * info) |
252b5132 RH |
2023 | { |
2024 | asection * s; | |
2025 | bfd_byte * foo; | |
2026 | struct elf32_arm_link_hash_table * globals; | |
2027 | ||
2028 | globals = elf32_arm_hash_table (info); | |
2029 | ||
2030 | BFD_ASSERT (globals != NULL); | |
2031 | ||
2032 | if (globals->arm_glue_size != 0) | |
2033 | { | |
2034 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); | |
2035 | ||
dc810e39 AM |
2036 | s = bfd_get_section_by_name (globals->bfd_of_glue_owner, |
2037 | ARM2THUMB_GLUE_SECTION_NAME); | |
252b5132 RH |
2038 | |
2039 | BFD_ASSERT (s != NULL); | |
2040 | ||
57e8b36a | 2041 | foo = bfd_alloc (globals->bfd_of_glue_owner, globals->arm_glue_size); |
252b5132 | 2042 | |
eea6121a | 2043 | s->size = globals->arm_glue_size; |
252b5132 RH |
2044 | s->contents = foo; |
2045 | } | |
2046 | ||
2047 | if (globals->thumb_glue_size != 0) | |
2048 | { | |
2049 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); | |
2050 | ||
2051 | s = bfd_get_section_by_name | |
2052 | (globals->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME); | |
2053 | ||
2054 | BFD_ASSERT (s != NULL); | |
2055 | ||
57e8b36a | 2056 | foo = bfd_alloc (globals->bfd_of_glue_owner, globals->thumb_glue_size); |
252b5132 | 2057 | |
eea6121a | 2058 | s->size = globals->thumb_glue_size; |
252b5132 RH |
2059 | s->contents = foo; |
2060 | } | |
2061 | ||
b34976b6 | 2062 | return TRUE; |
252b5132 RH |
2063 | } |
2064 | ||
2065 | static void | |
57e8b36a NC |
2066 | record_arm_to_thumb_glue (struct bfd_link_info * link_info, |
2067 | struct elf_link_hash_entry * h) | |
252b5132 RH |
2068 | { |
2069 | const char * name = h->root.root.string; | |
63b0f745 | 2070 | asection * s; |
252b5132 RH |
2071 | char * tmp_name; |
2072 | struct elf_link_hash_entry * myh; | |
14a793b2 | 2073 | struct bfd_link_hash_entry * bh; |
252b5132 | 2074 | struct elf32_arm_link_hash_table * globals; |
dc810e39 | 2075 | bfd_vma val; |
252b5132 RH |
2076 | |
2077 | globals = elf32_arm_hash_table (link_info); | |
2078 | ||
2079 | BFD_ASSERT (globals != NULL); | |
2080 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); | |
2081 | ||
2082 | s = bfd_get_section_by_name | |
2083 | (globals->bfd_of_glue_owner, ARM2THUMB_GLUE_SECTION_NAME); | |
2084 | ||
252b5132 RH |
2085 | BFD_ASSERT (s != NULL); |
2086 | ||
57e8b36a | 2087 | tmp_name = bfd_malloc ((bfd_size_type) strlen (name) + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1); |
252b5132 RH |
2088 | |
2089 | BFD_ASSERT (tmp_name); | |
2090 | ||
2091 | sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name); | |
2092 | ||
2093 | myh = elf_link_hash_lookup | |
b34976b6 | 2094 | (&(globals)->root, tmp_name, FALSE, FALSE, TRUE); |
252b5132 RH |
2095 | |
2096 | if (myh != NULL) | |
2097 | { | |
9b485d32 | 2098 | /* We've already seen this guy. */ |
252b5132 | 2099 | free (tmp_name); |
9b485d32 | 2100 | return; |
252b5132 RH |
2101 | } |
2102 | ||
57e8b36a NC |
2103 | /* The only trick here is using hash_table->arm_glue_size as the value. |
2104 | Even though the section isn't allocated yet, this is where we will be | |
2105 | putting it. */ | |
14a793b2 | 2106 | bh = NULL; |
dc810e39 AM |
2107 | val = globals->arm_glue_size + 1; |
2108 | _bfd_generic_link_add_one_symbol (link_info, globals->bfd_of_glue_owner, | |
2109 | tmp_name, BSF_GLOBAL, s, val, | |
b34976b6 | 2110 | NULL, TRUE, FALSE, &bh); |
252b5132 | 2111 | |
b7693d02 DJ |
2112 | myh = (struct elf_link_hash_entry *) bh; |
2113 | myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC); | |
2114 | myh->forced_local = 1; | |
2115 | ||
252b5132 RH |
2116 | free (tmp_name); |
2117 | ||
8f6277f5 PB |
2118 | if ((link_info->shared || globals->root.is_relocatable_executable)) |
2119 | globals->arm_glue_size += ARM2THUMB_PIC_GLUE_SIZE; | |
2120 | else | |
2121 | globals->arm_glue_size += ARM2THUMB_STATIC_GLUE_SIZE; | |
252b5132 RH |
2122 | |
2123 | return; | |
2124 | } | |
2125 | ||
2126 | static void | |
57e8b36a NC |
2127 | record_thumb_to_arm_glue (struct bfd_link_info *link_info, |
2128 | struct elf_link_hash_entry *h) | |
252b5132 RH |
2129 | { |
2130 | const char *name = h->root.root.string; | |
63b0f745 | 2131 | asection *s; |
252b5132 RH |
2132 | char *tmp_name; |
2133 | struct elf_link_hash_entry *myh; | |
14a793b2 | 2134 | struct bfd_link_hash_entry *bh; |
252b5132 | 2135 | struct elf32_arm_link_hash_table *hash_table; |
dc810e39 | 2136 | bfd_vma val; |
252b5132 RH |
2137 | |
2138 | hash_table = elf32_arm_hash_table (link_info); | |
2139 | ||
2140 | BFD_ASSERT (hash_table != NULL); | |
2141 | BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL); | |
2142 | ||
2143 | s = bfd_get_section_by_name | |
2144 | (hash_table->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME); | |
2145 | ||
2146 | BFD_ASSERT (s != NULL); | |
2147 | ||
57e8b36a NC |
2148 | tmp_name = bfd_malloc ((bfd_size_type) strlen (name) |
2149 | + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1); | |
252b5132 RH |
2150 | |
2151 | BFD_ASSERT (tmp_name); | |
2152 | ||
2153 | sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name); | |
2154 | ||
2155 | myh = elf_link_hash_lookup | |
b34976b6 | 2156 | (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE); |
252b5132 RH |
2157 | |
2158 | if (myh != NULL) | |
2159 | { | |
9b485d32 | 2160 | /* We've already seen this guy. */ |
252b5132 | 2161 | free (tmp_name); |
9b485d32 | 2162 | return; |
252b5132 RH |
2163 | } |
2164 | ||
14a793b2 | 2165 | bh = NULL; |
dc810e39 AM |
2166 | val = hash_table->thumb_glue_size + 1; |
2167 | _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner, | |
2168 | tmp_name, BSF_GLOBAL, s, val, | |
b34976b6 | 2169 | NULL, TRUE, FALSE, &bh); |
252b5132 | 2170 | |
9b485d32 | 2171 | /* If we mark it 'Thumb', the disassembler will do a better job. */ |
14a793b2 | 2172 | myh = (struct elf_link_hash_entry *) bh; |
b7693d02 DJ |
2173 | myh->type = ELF_ST_INFO (STB_LOCAL, STT_ARM_TFUNC); |
2174 | myh->forced_local = 1; | |
252b5132 RH |
2175 | |
2176 | free (tmp_name); | |
2177 | ||
252b5132 RH |
2178 | #define CHANGE_TO_ARM "__%s_change_to_arm" |
2179 | #define BACK_FROM_ARM "__%s_back_from_arm" | |
2180 | ||
9b485d32 | 2181 | /* Allocate another symbol to mark where we switch to Arm mode. */ |
57e8b36a NC |
2182 | tmp_name = bfd_malloc ((bfd_size_type) strlen (name) |
2183 | + strlen (CHANGE_TO_ARM) + 1); | |
252b5132 RH |
2184 | |
2185 | BFD_ASSERT (tmp_name); | |
2186 | ||
2187 | sprintf (tmp_name, CHANGE_TO_ARM, name); | |
2188 | ||
14a793b2 | 2189 | bh = NULL; |
dc810e39 AM |
2190 | val = hash_table->thumb_glue_size + 4, |
2191 | _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner, | |
2192 | tmp_name, BSF_LOCAL, s, val, | |
b34976b6 | 2193 | NULL, TRUE, FALSE, &bh); |
252b5132 RH |
2194 | |
2195 | free (tmp_name); | |
2196 | ||
2197 | hash_table->thumb_glue_size += THUMB2ARM_GLUE_SIZE; | |
2198 | ||
2199 | return; | |
2200 | } | |
2201 | ||
8afb0e02 NC |
2202 | /* Add the glue sections to ABFD. This function is called from the |
2203 | linker scripts in ld/emultempl/{armelf}.em. */ | |
9b485d32 | 2204 | |
b34976b6 | 2205 | bfd_boolean |
57e8b36a NC |
2206 | bfd_elf32_arm_add_glue_sections_to_bfd (bfd *abfd, |
2207 | struct bfd_link_info *info) | |
252b5132 | 2208 | { |
252b5132 RH |
2209 | flagword flags; |
2210 | asection *sec; | |
2211 | ||
8afb0e02 NC |
2212 | /* If we are only performing a partial |
2213 | link do not bother adding the glue. */ | |
1049f94e | 2214 | if (info->relocatable) |
b34976b6 | 2215 | return TRUE; |
252b5132 | 2216 | |
252b5132 RH |
2217 | sec = bfd_get_section_by_name (abfd, ARM2THUMB_GLUE_SECTION_NAME); |
2218 | ||
2219 | if (sec == NULL) | |
2220 | { | |
57db232e NC |
2221 | /* Note: we do not include the flag SEC_LINKER_CREATED, as this |
2222 | will prevent elf_link_input_bfd() from processing the contents | |
2223 | of this section. */ | |
811b4bf6 | 2224 | flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_CODE | SEC_READONLY; |
252b5132 | 2225 | |
3496cb2a L |
2226 | sec = bfd_make_section_with_flags (abfd, |
2227 | ARM2THUMB_GLUE_SECTION_NAME, | |
2228 | flags); | |
252b5132 RH |
2229 | |
2230 | if (sec == NULL | |
252b5132 | 2231 | || !bfd_set_section_alignment (abfd, sec, 2)) |
b34976b6 | 2232 | return FALSE; |
9a5aca8c | 2233 | |
57db232e NC |
2234 | /* Set the gc mark to prevent the section from being removed by garbage |
2235 | collection, despite the fact that no relocs refer to this section. */ | |
2236 | sec->gc_mark = 1; | |
252b5132 RH |
2237 | } |
2238 | ||
2239 | sec = bfd_get_section_by_name (abfd, THUMB2ARM_GLUE_SECTION_NAME); | |
2240 | ||
2241 | if (sec == NULL) | |
2242 | { | |
57e8b36a NC |
2243 | flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY |
2244 | | SEC_CODE | SEC_READONLY; | |
252b5132 | 2245 | |
3496cb2a L |
2246 | sec = bfd_make_section_with_flags (abfd, |
2247 | THUMB2ARM_GLUE_SECTION_NAME, | |
2248 | flags); | |
252b5132 RH |
2249 | |
2250 | if (sec == NULL | |
252b5132 | 2251 | || !bfd_set_section_alignment (abfd, sec, 2)) |
b34976b6 | 2252 | return FALSE; |
9a5aca8c | 2253 | |
57db232e | 2254 | sec->gc_mark = 1; |
252b5132 RH |
2255 | } |
2256 | ||
b34976b6 | 2257 | return TRUE; |
8afb0e02 NC |
2258 | } |
2259 | ||
2260 | /* Select a BFD to be used to hold the sections used by the glue code. | |
2261 | This function is called from the linker scripts in ld/emultempl/ | |
2262 | {armelf/pe}.em */ | |
2263 | ||
b34976b6 | 2264 | bfd_boolean |
57e8b36a | 2265 | bfd_elf32_arm_get_bfd_for_interworking (bfd *abfd, struct bfd_link_info *info) |
8afb0e02 NC |
2266 | { |
2267 | struct elf32_arm_link_hash_table *globals; | |
2268 | ||
2269 | /* If we are only performing a partial link | |
2270 | do not bother getting a bfd to hold the glue. */ | |
1049f94e | 2271 | if (info->relocatable) |
b34976b6 | 2272 | return TRUE; |
8afb0e02 | 2273 | |
b7693d02 DJ |
2274 | /* Make sure we don't attach the glue sections to a dynamic object. */ |
2275 | BFD_ASSERT (!(abfd->flags & DYNAMIC)); | |
2276 | ||
8afb0e02 NC |
2277 | globals = elf32_arm_hash_table (info); |
2278 | ||
2279 | BFD_ASSERT (globals != NULL); | |
2280 | ||
2281 | if (globals->bfd_of_glue_owner != NULL) | |
b34976b6 | 2282 | return TRUE; |
8afb0e02 | 2283 | |
252b5132 RH |
2284 | /* Save the bfd for later use. */ |
2285 | globals->bfd_of_glue_owner = abfd; | |
cedb70c5 | 2286 | |
b34976b6 | 2287 | return TRUE; |
252b5132 RH |
2288 | } |
2289 | ||
b34976b6 | 2290 | bfd_boolean |
57e8b36a NC |
2291 | bfd_elf32_arm_process_before_allocation (bfd *abfd, |
2292 | struct bfd_link_info *link_info, | |
eb043451 | 2293 | int byteswap_code) |
252b5132 RH |
2294 | { |
2295 | Elf_Internal_Shdr *symtab_hdr; | |
6cdc0ccc | 2296 | Elf_Internal_Rela *internal_relocs = NULL; |
252b5132 RH |
2297 | Elf_Internal_Rela *irel, *irelend; |
2298 | bfd_byte *contents = NULL; | |
252b5132 RH |
2299 | |
2300 | asection *sec; | |
2301 | struct elf32_arm_link_hash_table *globals; | |
2302 | ||
2303 | /* If we are only performing a partial link do not bother | |
2304 | to construct any glue. */ | |
1049f94e | 2305 | if (link_info->relocatable) |
b34976b6 | 2306 | return TRUE; |
252b5132 RH |
2307 | |
2308 | /* Here we have a bfd that is to be included on the link. We have a hook | |
2309 | to do reloc rummaging, before section sizes are nailed down. */ | |
252b5132 RH |
2310 | globals = elf32_arm_hash_table (link_info); |
2311 | ||
2312 | BFD_ASSERT (globals != NULL); | |
2313 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); | |
2314 | ||
e489d0ae PB |
2315 | if (byteswap_code && !bfd_big_endian (abfd)) |
2316 | { | |
d003868e AM |
2317 | _bfd_error_handler (_("%B: BE8 images only valid in big-endian mode."), |
2318 | abfd); | |
e489d0ae PB |
2319 | return FALSE; |
2320 | } | |
2321 | globals->byteswap_code = byteswap_code; | |
f21f3fe0 | 2322 | |
252b5132 RH |
2323 | /* Rummage around all the relocs and map the glue vectors. */ |
2324 | sec = abfd->sections; | |
2325 | ||
2326 | if (sec == NULL) | |
b34976b6 | 2327 | return TRUE; |
252b5132 RH |
2328 | |
2329 | for (; sec != NULL; sec = sec->next) | |
2330 | { | |
2331 | if (sec->reloc_count == 0) | |
2332 | continue; | |
2333 | ||
2334 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; | |
252b5132 | 2335 | |
9b485d32 | 2336 | /* Load the relocs. */ |
6cdc0ccc | 2337 | internal_relocs |
57e8b36a | 2338 | = _bfd_elf_link_read_relocs (abfd, sec, (void *) NULL, |
45d6a902 | 2339 | (Elf_Internal_Rela *) NULL, FALSE); |
252b5132 | 2340 | |
6cdc0ccc AM |
2341 | if (internal_relocs == NULL) |
2342 | goto error_return; | |
252b5132 | 2343 | |
6cdc0ccc AM |
2344 | irelend = internal_relocs + sec->reloc_count; |
2345 | for (irel = internal_relocs; irel < irelend; irel++) | |
252b5132 RH |
2346 | { |
2347 | long r_type; | |
2348 | unsigned long r_index; | |
252b5132 RH |
2349 | |
2350 | struct elf_link_hash_entry *h; | |
2351 | ||
2352 | r_type = ELF32_R_TYPE (irel->r_info); | |
2353 | r_index = ELF32_R_SYM (irel->r_info); | |
2354 | ||
9b485d32 | 2355 | /* These are the only relocation types we care about. */ |
ba96a88f | 2356 | if ( r_type != R_ARM_PC24 |
b7693d02 | 2357 | && r_type != R_ARM_PLT32 |
5b5bb741 PB |
2358 | && r_type != R_ARM_CALL |
2359 | && r_type != R_ARM_JUMP24 | |
c19d1205 | 2360 | && r_type != R_ARM_THM_CALL) |
252b5132 RH |
2361 | continue; |
2362 | ||
2363 | /* Get the section contents if we haven't done so already. */ | |
2364 | if (contents == NULL) | |
2365 | { | |
2366 | /* Get cached copy if it exists. */ | |
2367 | if (elf_section_data (sec)->this_hdr.contents != NULL) | |
2368 | contents = elf_section_data (sec)->this_hdr.contents; | |
2369 | else | |
2370 | { | |
2371 | /* Go get them off disk. */ | |
57e8b36a | 2372 | if (! bfd_malloc_and_get_section (abfd, sec, &contents)) |
252b5132 RH |
2373 | goto error_return; |
2374 | } | |
2375 | } | |
2376 | ||
a7c10850 | 2377 | /* If the relocation is not against a symbol it cannot concern us. */ |
252b5132 RH |
2378 | h = NULL; |
2379 | ||
9b485d32 | 2380 | /* We don't care about local symbols. */ |
252b5132 RH |
2381 | if (r_index < symtab_hdr->sh_info) |
2382 | continue; | |
2383 | ||
9b485d32 | 2384 | /* This is an external symbol. */ |
252b5132 RH |
2385 | r_index -= symtab_hdr->sh_info; |
2386 | h = (struct elf_link_hash_entry *) | |
2387 | elf_sym_hashes (abfd)[r_index]; | |
2388 | ||
2389 | /* If the relocation is against a static symbol it must be within | |
2390 | the current section and so cannot be a cross ARM/Thumb relocation. */ | |
2391 | if (h == NULL) | |
2392 | continue; | |
2393 | ||
b7693d02 DJ |
2394 | /* If the call will go through a PLT entry then we do not need |
2395 | glue. */ | |
2396 | if (globals->splt != NULL && h->plt.offset != (bfd_vma) -1) | |
2397 | continue; | |
2398 | ||
252b5132 RH |
2399 | switch (r_type) |
2400 | { | |
2401 | case R_ARM_PC24: | |
c6596c5e | 2402 | case R_ARM_PLT32: |
5b5bb741 PB |
2403 | case R_ARM_CALL: |
2404 | case R_ARM_JUMP24: | |
252b5132 | 2405 | /* This one is a call from arm code. We need to look up |
2f0ca46a | 2406 | the target of the call. If it is a thumb target, we |
252b5132 | 2407 | insert glue. */ |
252b5132 RH |
2408 | if (ELF_ST_TYPE(h->type) == STT_ARM_TFUNC) |
2409 | record_arm_to_thumb_glue (link_info, h); | |
2410 | break; | |
2411 | ||
c19d1205 | 2412 | case R_ARM_THM_CALL: |
f21f3fe0 | 2413 | /* This one is a call from thumb code. We look |
2f0ca46a | 2414 | up the target of the call. If it is not a thumb |
bcbdc74c | 2415 | target, we insert glue. */ |
252b5132 RH |
2416 | if (ELF_ST_TYPE (h->type) != STT_ARM_TFUNC) |
2417 | record_thumb_to_arm_glue (link_info, h); | |
2418 | break; | |
2419 | ||
2420 | default: | |
c6596c5e | 2421 | abort (); |
252b5132 RH |
2422 | } |
2423 | } | |
6cdc0ccc AM |
2424 | |
2425 | if (contents != NULL | |
2426 | && elf_section_data (sec)->this_hdr.contents != contents) | |
2427 | free (contents); | |
2428 | contents = NULL; | |
2429 | ||
2430 | if (internal_relocs != NULL | |
2431 | && elf_section_data (sec)->relocs != internal_relocs) | |
2432 | free (internal_relocs); | |
2433 | internal_relocs = NULL; | |
252b5132 RH |
2434 | } |
2435 | ||
b34976b6 | 2436 | return TRUE; |
9a5aca8c | 2437 | |
252b5132 | 2438 | error_return: |
6cdc0ccc AM |
2439 | if (contents != NULL |
2440 | && elf_section_data (sec)->this_hdr.contents != contents) | |
2441 | free (contents); | |
2442 | if (internal_relocs != NULL | |
2443 | && elf_section_data (sec)->relocs != internal_relocs) | |
2444 | free (internal_relocs); | |
9a5aca8c | 2445 | |
b34976b6 | 2446 | return FALSE; |
252b5132 | 2447 | } |
7e392df6 | 2448 | #endif |
252b5132 | 2449 | |
eb043451 | 2450 | |
eb043451 PB |
2451 | /* Set target relocation values needed during linking. */ |
2452 | ||
2453 | void | |
2454 | bfd_elf32_arm_set_target_relocs (struct bfd_link_info *link_info, | |
2455 | int target1_is_rel, | |
319850b4 | 2456 | char * target2_type, |
33bfe774 JB |
2457 | int fix_v4bx, |
2458 | int use_blx) | |
eb043451 PB |
2459 | { |
2460 | struct elf32_arm_link_hash_table *globals; | |
2461 | ||
2462 | globals = elf32_arm_hash_table (link_info); | |
2463 | ||
2464 | globals->target1_is_rel = target1_is_rel; | |
2465 | if (strcmp (target2_type, "rel") == 0) | |
2466 | globals->target2_reloc = R_ARM_REL32; | |
eeac373a PB |
2467 | else if (strcmp (target2_type, "abs") == 0) |
2468 | globals->target2_reloc = R_ARM_ABS32; | |
eb043451 PB |
2469 | else if (strcmp (target2_type, "got-rel") == 0) |
2470 | globals->target2_reloc = R_ARM_GOT_PREL; | |
2471 | else | |
2472 | { | |
2473 | _bfd_error_handler (_("Invalid TARGET2 relocation type '%s'."), | |
2474 | target2_type); | |
2475 | } | |
319850b4 | 2476 | globals->fix_v4bx = fix_v4bx; |
33bfe774 | 2477 | globals->use_blx |= use_blx; |
eb043451 | 2478 | } |
eb043451 | 2479 | |
252b5132 RH |
2480 | /* The thumb form of a long branch is a bit finicky, because the offset |
2481 | encoding is split over two fields, each in it's own instruction. They | |
f21f3fe0 | 2482 | can occur in any order. So given a thumb form of long branch, and an |
252b5132 | 2483 | offset, insert the offset into the thumb branch and return finished |
f21f3fe0 | 2484 | instruction. |
252b5132 | 2485 | |
f21f3fe0 | 2486 | It takes two thumb instructions to encode the target address. Each has |
4cc11e76 | 2487 | 11 bits to invest. The upper 11 bits are stored in one (identified by |
f21f3fe0 UD |
2488 | H-0.. see below), the lower 11 bits are stored in the other (identified |
2489 | by H-1). | |
252b5132 | 2490 | |
f21f3fe0 | 2491 | Combine together and shifted left by 1 (it's a half word address) and |
252b5132 RH |
2492 | there you have it. |
2493 | ||
2494 | Op: 1111 = F, | |
2495 | H-0, upper address-0 = 000 | |
2496 | Op: 1111 = F, | |
2497 | H-1, lower address-0 = 800 | |
2498 | ||
f21f3fe0 | 2499 | They can be ordered either way, but the arm tools I've seen always put |
252b5132 RH |
2500 | the lower one first. It probably doesn't matter. krk@cygnus.com |
2501 | ||
2502 | XXX: Actually the order does matter. The second instruction (H-1) | |
2503 | moves the computed address into the PC, so it must be the second one | |
2504 | in the sequence. The problem, however is that whilst little endian code | |
2505 | stores the instructions in HI then LOW order, big endian code does the | |
dfc5f959 | 2506 | reverse. nickc@cygnus.com. */ |
252b5132 | 2507 | |
dfc5f959 NC |
2508 | #define LOW_HI_ORDER 0xF800F000 |
2509 | #define HI_LOW_ORDER 0xF000F800 | |
252b5132 RH |
2510 | |
2511 | static insn32 | |
57e8b36a | 2512 | insert_thumb_branch (insn32 br_insn, int rel_off) |
252b5132 RH |
2513 | { |
2514 | unsigned int low_bits; | |
2515 | unsigned int high_bits; | |
2516 | ||
252b5132 RH |
2517 | BFD_ASSERT ((rel_off & 1) != 1); |
2518 | ||
dfc5f959 NC |
2519 | rel_off >>= 1; /* Half word aligned address. */ |
2520 | low_bits = rel_off & 0x000007FF; /* The bottom 11 bits. */ | |
2521 | high_bits = (rel_off >> 11) & 0x000007FF; /* The top 11 bits. */ | |
252b5132 RH |
2522 | |
2523 | if ((br_insn & LOW_HI_ORDER) == LOW_HI_ORDER) | |
2524 | br_insn = LOW_HI_ORDER | (low_bits << 16) | high_bits; | |
2525 | else if ((br_insn & HI_LOW_ORDER) == HI_LOW_ORDER) | |
2526 | br_insn = HI_LOW_ORDER | (high_bits << 16) | low_bits; | |
2527 | else | |
9b485d32 | 2528 | /* FIXME: abort is probably not the right call. krk@cygnus.com */ |
57e8b36a | 2529 | abort (); /* Error - not a valid branch instruction form. */ |
252b5132 | 2530 | |
252b5132 RH |
2531 | return br_insn; |
2532 | } | |
2533 | ||
9b485d32 NC |
2534 | /* Thumb code calling an ARM function. */ |
2535 | ||
252b5132 | 2536 | static int |
57e8b36a NC |
2537 | elf32_thumb_to_arm_stub (struct bfd_link_info * info, |
2538 | const char * name, | |
2539 | bfd * input_bfd, | |
2540 | bfd * output_bfd, | |
2541 | asection * input_section, | |
2542 | bfd_byte * hit_data, | |
2543 | asection * sym_sec, | |
2544 | bfd_vma offset, | |
2545 | bfd_signed_vma addend, | |
2546 | bfd_vma val) | |
252b5132 | 2547 | { |
bcbdc74c | 2548 | asection * s = 0; |
dc810e39 | 2549 | bfd_vma my_offset; |
252b5132 RH |
2550 | unsigned long int tmp; |
2551 | long int ret_offset; | |
bcbdc74c NC |
2552 | struct elf_link_hash_entry * myh; |
2553 | struct elf32_arm_link_hash_table * globals; | |
252b5132 RH |
2554 | |
2555 | myh = find_thumb_glue (info, name, input_bfd); | |
2556 | if (myh == NULL) | |
b34976b6 | 2557 | return FALSE; |
252b5132 RH |
2558 | |
2559 | globals = elf32_arm_hash_table (info); | |
2560 | ||
2561 | BFD_ASSERT (globals != NULL); | |
2562 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); | |
2563 | ||
2564 | my_offset = myh->root.u.def.value; | |
2565 | ||
2566 | s = bfd_get_section_by_name (globals->bfd_of_glue_owner, | |
2567 | THUMB2ARM_GLUE_SECTION_NAME); | |
2568 | ||
2569 | BFD_ASSERT (s != NULL); | |
2570 | BFD_ASSERT (s->contents != NULL); | |
2571 | BFD_ASSERT (s->output_section != NULL); | |
2572 | ||
2573 | if ((my_offset & 0x01) == 0x01) | |
2574 | { | |
2575 | if (sym_sec != NULL | |
2576 | && sym_sec->owner != NULL | |
2577 | && !INTERWORK_FLAG (sym_sec->owner)) | |
2578 | { | |
8f615d07 | 2579 | (*_bfd_error_handler) |
d003868e AM |
2580 | (_("%B(%s): warning: interworking not enabled.\n" |
2581 | " first occurrence: %B: thumb call to arm"), | |
2582 | sym_sec->owner, input_bfd, name); | |
252b5132 | 2583 | |
b34976b6 | 2584 | return FALSE; |
252b5132 RH |
2585 | } |
2586 | ||
2587 | --my_offset; | |
2588 | myh->root.u.def.value = my_offset; | |
2589 | ||
dc810e39 | 2590 | bfd_put_16 (output_bfd, (bfd_vma) t2a1_bx_pc_insn, |
252b5132 RH |
2591 | s->contents + my_offset); |
2592 | ||
dc810e39 | 2593 | bfd_put_16 (output_bfd, (bfd_vma) t2a2_noop_insn, |
252b5132 RH |
2594 | s->contents + my_offset + 2); |
2595 | ||
2596 | ret_offset = | |
9b485d32 NC |
2597 | /* Address of destination of the stub. */ |
2598 | ((bfd_signed_vma) val) | |
252b5132 | 2599 | - ((bfd_signed_vma) |
57e8b36a NC |
2600 | /* Offset from the start of the current section |
2601 | to the start of the stubs. */ | |
9b485d32 NC |
2602 | (s->output_offset |
2603 | /* Offset of the start of this stub from the start of the stubs. */ | |
2604 | + my_offset | |
2605 | /* Address of the start of the current section. */ | |
2606 | + s->output_section->vma) | |
2607 | /* The branch instruction is 4 bytes into the stub. */ | |
2608 | + 4 | |
2609 | /* ARM branches work from the pc of the instruction + 8. */ | |
2610 | + 8); | |
252b5132 RH |
2611 | |
2612 | bfd_put_32 (output_bfd, | |
dc810e39 | 2613 | (bfd_vma) t2a3_b_insn | ((ret_offset >> 2) & 0x00FFFFFF), |
252b5132 RH |
2614 | s->contents + my_offset + 4); |
2615 | } | |
2616 | ||
2617 | BFD_ASSERT (my_offset <= globals->thumb_glue_size); | |
2618 | ||
427bfd90 NC |
2619 | /* Now go back and fix up the original BL insn to point to here. */ |
2620 | ret_offset = | |
2621 | /* Address of where the stub is located. */ | |
2622 | (s->output_section->vma + s->output_offset + my_offset) | |
2623 | /* Address of where the BL is located. */ | |
57e8b36a NC |
2624 | - (input_section->output_section->vma + input_section->output_offset |
2625 | + offset) | |
427bfd90 NC |
2626 | /* Addend in the relocation. */ |
2627 | - addend | |
2628 | /* Biassing for PC-relative addressing. */ | |
2629 | - 8; | |
252b5132 RH |
2630 | |
2631 | tmp = bfd_get_32 (input_bfd, hit_data | |
2632 | - input_section->vma); | |
2633 | ||
2634 | bfd_put_32 (output_bfd, | |
dc810e39 | 2635 | (bfd_vma) insert_thumb_branch (tmp, ret_offset), |
252b5132 RH |
2636 | hit_data - input_section->vma); |
2637 | ||
b34976b6 | 2638 | return TRUE; |
252b5132 RH |
2639 | } |
2640 | ||
9b485d32 NC |
2641 | /* Arm code calling a Thumb function. */ |
2642 | ||
252b5132 | 2643 | static int |
57e8b36a NC |
2644 | elf32_arm_to_thumb_stub (struct bfd_link_info * info, |
2645 | const char * name, | |
2646 | bfd * input_bfd, | |
2647 | bfd * output_bfd, | |
2648 | asection * input_section, | |
2649 | bfd_byte * hit_data, | |
2650 | asection * sym_sec, | |
2651 | bfd_vma offset, | |
2652 | bfd_signed_vma addend, | |
2653 | bfd_vma val) | |
252b5132 RH |
2654 | { |
2655 | unsigned long int tmp; | |
dc810e39 | 2656 | bfd_vma my_offset; |
bcbdc74c | 2657 | asection * s; |
252b5132 | 2658 | long int ret_offset; |
bcbdc74c NC |
2659 | struct elf_link_hash_entry * myh; |
2660 | struct elf32_arm_link_hash_table * globals; | |
252b5132 RH |
2661 | |
2662 | myh = find_arm_glue (info, name, input_bfd); | |
2663 | if (myh == NULL) | |
b34976b6 | 2664 | return FALSE; |
252b5132 RH |
2665 | |
2666 | globals = elf32_arm_hash_table (info); | |
2667 | ||
2668 | BFD_ASSERT (globals != NULL); | |
2669 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); | |
2670 | ||
2671 | my_offset = myh->root.u.def.value; | |
2672 | s = bfd_get_section_by_name (globals->bfd_of_glue_owner, | |
2673 | ARM2THUMB_GLUE_SECTION_NAME); | |
2674 | BFD_ASSERT (s != NULL); | |
2675 | BFD_ASSERT (s->contents != NULL); | |
2676 | BFD_ASSERT (s->output_section != NULL); | |
2677 | ||
2678 | if ((my_offset & 0x01) == 0x01) | |
2679 | { | |
2680 | if (sym_sec != NULL | |
2681 | && sym_sec->owner != NULL | |
2682 | && !INTERWORK_FLAG (sym_sec->owner)) | |
2683 | { | |
8f615d07 | 2684 | (*_bfd_error_handler) |
d003868e AM |
2685 | (_("%B(%s): warning: interworking not enabled.\n" |
2686 | " first occurrence: %B: arm call to thumb"), | |
2687 | sym_sec->owner, input_bfd, name); | |
252b5132 | 2688 | } |
9b485d32 | 2689 | |
252b5132 RH |
2690 | --my_offset; |
2691 | myh->root.u.def.value = my_offset; | |
2692 | ||
8f6277f5 PB |
2693 | if ((info->shared || globals->root.is_relocatable_executable)) |
2694 | { | |
2695 | /* For relocatable objects we can't use absolute addresses, | |
2696 | so construct the address from a relative offset. */ | |
2697 | /* TODO: If the offset is small it's probably worth | |
2698 | constructing the address with adds. */ | |
2699 | bfd_put_32 (output_bfd, (bfd_vma) a2t1p_ldr_insn, | |
2700 | s->contents + my_offset); | |
2701 | bfd_put_32 (output_bfd, (bfd_vma) a2t2p_add_pc_insn, | |
2702 | s->contents + my_offset + 4); | |
2703 | bfd_put_32 (output_bfd, (bfd_vma) a2t3p_bx_r12_insn, | |
2704 | s->contents + my_offset + 8); | |
2705 | /* Adjust the offset by 4 for the position of the add, | |
2706 | and 8 for the pipeline offset. */ | |
2707 | ret_offset = (val - (s->output_offset | |
2708 | + s->output_section->vma | |
2709 | + my_offset + 12)) | |
2710 | | 1; | |
2711 | bfd_put_32 (output_bfd, ret_offset, | |
2712 | s->contents + my_offset + 12); | |
2713 | } | |
2714 | else | |
2715 | { | |
2716 | bfd_put_32 (output_bfd, (bfd_vma) a2t1_ldr_insn, | |
2717 | s->contents + my_offset); | |
252b5132 | 2718 | |
8f6277f5 PB |
2719 | bfd_put_32 (output_bfd, (bfd_vma) a2t2_bx_r12_insn, |
2720 | s->contents + my_offset + 4); | |
252b5132 | 2721 | |
8f6277f5 PB |
2722 | /* It's a thumb address. Add the low order bit. */ |
2723 | bfd_put_32 (output_bfd, val | a2t3_func_addr_insn, | |
2724 | s->contents + my_offset + 8); | |
2725 | } | |
252b5132 RH |
2726 | } |
2727 | ||
2728 | BFD_ASSERT (my_offset <= globals->arm_glue_size); | |
2729 | ||
2730 | tmp = bfd_get_32 (input_bfd, hit_data); | |
2731 | tmp = tmp & 0xFF000000; | |
2732 | ||
9b485d32 | 2733 | /* Somehow these are both 4 too far, so subtract 8. */ |
dc810e39 AM |
2734 | ret_offset = (s->output_offset |
2735 | + my_offset | |
2736 | + s->output_section->vma | |
2737 | - (input_section->output_offset | |
2738 | + input_section->output_section->vma | |
2739 | + offset + addend) | |
2740 | - 8); | |
9a5aca8c | 2741 | |
252b5132 RH |
2742 | tmp = tmp | ((ret_offset >> 2) & 0x00FFFFFF); |
2743 | ||
dc810e39 | 2744 | bfd_put_32 (output_bfd, (bfd_vma) tmp, hit_data - input_section->vma); |
252b5132 | 2745 | |
b34976b6 | 2746 | return TRUE; |
252b5132 RH |
2747 | } |
2748 | ||
eb043451 PB |
2749 | /* Some relocations map to different relocations depending on the |
2750 | target. Return the real relocation. */ | |
2751 | static int | |
2752 | arm_real_reloc_type (struct elf32_arm_link_hash_table * globals, | |
2753 | int r_type) | |
2754 | { | |
2755 | switch (r_type) | |
2756 | { | |
2757 | case R_ARM_TARGET1: | |
2758 | if (globals->target1_is_rel) | |
2759 | return R_ARM_REL32; | |
2760 | else | |
2761 | return R_ARM_ABS32; | |
2762 | ||
2763 | case R_ARM_TARGET2: | |
2764 | return globals->target2_reloc; | |
2765 | ||
2766 | default: | |
2767 | return r_type; | |
2768 | } | |
2769 | } | |
eb043451 | 2770 | |
ba93b8ac DJ |
2771 | /* Return the base VMA address which should be subtracted from real addresses |
2772 | when resolving @dtpoff relocation. | |
2773 | This is PT_TLS segment p_vaddr. */ | |
2774 | ||
2775 | static bfd_vma | |
2776 | dtpoff_base (struct bfd_link_info *info) | |
2777 | { | |
2778 | /* If tls_sec is NULL, we should have signalled an error already. */ | |
2779 | if (elf_hash_table (info)->tls_sec == NULL) | |
2780 | return 0; | |
2781 | return elf_hash_table (info)->tls_sec->vma; | |
2782 | } | |
2783 | ||
2784 | /* Return the relocation value for @tpoff relocation | |
2785 | if STT_TLS virtual address is ADDRESS. */ | |
2786 | ||
2787 | static bfd_vma | |
2788 | tpoff (struct bfd_link_info *info, bfd_vma address) | |
2789 | { | |
2790 | struct elf_link_hash_table *htab = elf_hash_table (info); | |
2791 | bfd_vma base; | |
2792 | ||
2793 | /* If tls_sec is NULL, we should have signalled an error already. */ | |
2794 | if (htab->tls_sec == NULL) | |
2795 | return 0; | |
2796 | base = align_power ((bfd_vma) TCB_SIZE, htab->tls_sec->alignment_power); | |
2797 | return address - htab->tls_sec->vma + base; | |
2798 | } | |
2799 | ||
252b5132 | 2800 | /* Perform a relocation as part of a final link. */ |
9b485d32 | 2801 | |
252b5132 | 2802 | static bfd_reloc_status_type |
57e8b36a NC |
2803 | elf32_arm_final_link_relocate (reloc_howto_type * howto, |
2804 | bfd * input_bfd, | |
2805 | bfd * output_bfd, | |
2806 | asection * input_section, | |
2807 | bfd_byte * contents, | |
2808 | Elf_Internal_Rela * rel, | |
2809 | bfd_vma value, | |
2810 | struct bfd_link_info * info, | |
2811 | asection * sym_sec, | |
2812 | const char * sym_name, | |
2813 | int sym_flags, | |
0945cdfd DJ |
2814 | struct elf_link_hash_entry * h, |
2815 | bfd_boolean * unresolved_reloc_p) | |
252b5132 RH |
2816 | { |
2817 | unsigned long r_type = howto->type; | |
2818 | unsigned long r_symndx; | |
2819 | bfd_byte * hit_data = contents + rel->r_offset; | |
2820 | bfd * dynobj = NULL; | |
2821 | Elf_Internal_Shdr * symtab_hdr; | |
2822 | struct elf_link_hash_entry ** sym_hashes; | |
2823 | bfd_vma * local_got_offsets; | |
2824 | asection * sgot = NULL; | |
2825 | asection * splt = NULL; | |
2826 | asection * sreloc = NULL; | |
252b5132 | 2827 | bfd_vma addend; |
ba96a88f NC |
2828 | bfd_signed_vma signed_addend; |
2829 | struct elf32_arm_link_hash_table * globals; | |
f21f3fe0 | 2830 | |
9c504268 PB |
2831 | globals = elf32_arm_hash_table (info); |
2832 | ||
9c504268 PB |
2833 | /* Some relocation type map to different relocations depending on the |
2834 | target. We pick the right one here. */ | |
eb043451 PB |
2835 | r_type = arm_real_reloc_type (globals, r_type); |
2836 | if (r_type != howto->type) | |
2837 | howto = elf32_arm_howto_from_type (r_type); | |
9c504268 | 2838 | |
cac15327 NC |
2839 | /* If the start address has been set, then set the EF_ARM_HASENTRY |
2840 | flag. Setting this more than once is redundant, but the cost is | |
2841 | not too high, and it keeps the code simple. | |
99e4ae17 | 2842 | |
cac15327 NC |
2843 | The test is done here, rather than somewhere else, because the |
2844 | start address is only set just before the final link commences. | |
2845 | ||
2846 | Note - if the user deliberately sets a start address of 0, the | |
2847 | flag will not be set. */ | |
2848 | if (bfd_get_start_address (output_bfd) != 0) | |
2849 | elf_elfheader (output_bfd)->e_flags |= EF_ARM_HASENTRY; | |
99e4ae17 | 2850 | |
252b5132 RH |
2851 | dynobj = elf_hash_table (info)->dynobj; |
2852 | if (dynobj) | |
2853 | { | |
2854 | sgot = bfd_get_section_by_name (dynobj, ".got"); | |
2855 | splt = bfd_get_section_by_name (dynobj, ".plt"); | |
2856 | } | |
2857 | symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr; | |
2858 | sym_hashes = elf_sym_hashes (input_bfd); | |
2859 | local_got_offsets = elf_local_got_offsets (input_bfd); | |
2860 | r_symndx = ELF32_R_SYM (rel->r_info); | |
2861 | ||
4e7fd91e | 2862 | if (globals->use_rel) |
ba96a88f | 2863 | { |
4e7fd91e PB |
2864 | addend = bfd_get_32 (input_bfd, hit_data) & howto->src_mask; |
2865 | ||
2866 | if (addend & ((howto->src_mask + 1) >> 1)) | |
2867 | { | |
2868 | signed_addend = -1; | |
2869 | signed_addend &= ~ howto->src_mask; | |
2870 | signed_addend |= addend; | |
2871 | } | |
2872 | else | |
2873 | signed_addend = addend; | |
ba96a88f NC |
2874 | } |
2875 | else | |
4e7fd91e | 2876 | addend = signed_addend = rel->r_addend; |
f21f3fe0 | 2877 | |
252b5132 RH |
2878 | switch (r_type) |
2879 | { | |
2880 | case R_ARM_NONE: | |
28a094c2 DJ |
2881 | /* We don't need to find a value for this symbol. It's just a |
2882 | marker. */ | |
2883 | *unresolved_reloc_p = FALSE; | |
252b5132 RH |
2884 | return bfd_reloc_ok; |
2885 | ||
2886 | case R_ARM_PC24: | |
2887 | case R_ARM_ABS32: | |
2888 | case R_ARM_REL32: | |
5b5bb741 PB |
2889 | case R_ARM_CALL: |
2890 | case R_ARM_JUMP24: | |
dfc5f959 | 2891 | case R_ARM_XPC25: |
eb043451 | 2892 | case R_ARM_PREL31: |
7359ea65 | 2893 | case R_ARM_PLT32: |
5e681ec4 PB |
2894 | /* r_symndx will be zero only for relocs against symbols |
2895 | from removed linkonce sections, or sections discarded by | |
2896 | a linker script. */ | |
2897 | if (r_symndx == 0) | |
2898 | return bfd_reloc_ok; | |
2899 | ||
7359ea65 DJ |
2900 | /* Handle relocations which should use the PLT entry. ABS32/REL32 |
2901 | will use the symbol's value, which may point to a PLT entry, but we | |
2902 | don't need to handle that here. If we created a PLT entry, all | |
2903 | branches in this object should go to it. */ | |
ee06dc07 | 2904 | if ((r_type != R_ARM_ABS32 && r_type != R_ARM_REL32) |
7359ea65 | 2905 | && h != NULL |
c84cd8ee | 2906 | && splt != NULL |
7359ea65 DJ |
2907 | && h->plt.offset != (bfd_vma) -1) |
2908 | { | |
c84cd8ee DJ |
2909 | /* If we've created a .plt section, and assigned a PLT entry to |
2910 | this function, it should not be known to bind locally. If | |
2911 | it were, we would have cleared the PLT entry. */ | |
7359ea65 DJ |
2912 | BFD_ASSERT (!SYMBOL_CALLS_LOCAL (info, h)); |
2913 | ||
2914 | value = (splt->output_section->vma | |
2915 | + splt->output_offset | |
2916 | + h->plt.offset); | |
0945cdfd | 2917 | *unresolved_reloc_p = FALSE; |
7359ea65 DJ |
2918 | return _bfd_final_link_relocate (howto, input_bfd, input_section, |
2919 | contents, rel->r_offset, value, | |
2920 | (bfd_vma) 0); | |
2921 | } | |
2922 | ||
67687978 PB |
2923 | /* When generating a shared object or relocatable executable, these |
2924 | relocations are copied into the output file to be resolved at | |
2925 | run time. */ | |
2926 | if ((info->shared || globals->root.is_relocatable_executable) | |
7359ea65 | 2927 | && (input_section->flags & SEC_ALLOC) |
ee06dc07 PB |
2928 | && (r_type != R_ARM_REL32 |
2929 | || !SYMBOL_CALLS_LOCAL (info, h)) | |
7359ea65 DJ |
2930 | && (h == NULL |
2931 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
2932 | || h->root.type != bfd_link_hash_undefweak) | |
2933 | && r_type != R_ARM_PC24 | |
5b5bb741 PB |
2934 | && r_type != R_ARM_CALL |
2935 | && r_type != R_ARM_JUMP24 | |
ee06dc07 | 2936 | && r_type != R_ARM_PREL31 |
7359ea65 | 2937 | && r_type != R_ARM_PLT32) |
252b5132 | 2938 | { |
947216bf AM |
2939 | Elf_Internal_Rela outrel; |
2940 | bfd_byte *loc; | |
b34976b6 | 2941 | bfd_boolean skip, relocate; |
f21f3fe0 | 2942 | |
0945cdfd DJ |
2943 | *unresolved_reloc_p = FALSE; |
2944 | ||
252b5132 RH |
2945 | if (sreloc == NULL) |
2946 | { | |
2947 | const char * name; | |
f21f3fe0 | 2948 | |
252b5132 RH |
2949 | name = (bfd_elf_string_from_elf_section |
2950 | (input_bfd, | |
2951 | elf_elfheader (input_bfd)->e_shstrndx, | |
2952 | elf_section_data (input_section)->rel_hdr.sh_name)); | |
2953 | if (name == NULL) | |
2954 | return bfd_reloc_notsupported; | |
f21f3fe0 | 2955 | |
252b5132 RH |
2956 | BFD_ASSERT (strncmp (name, ".rel", 4) == 0 |
2957 | && strcmp (bfd_get_section_name (input_bfd, | |
2958 | input_section), | |
2959 | name + 4) == 0); | |
f21f3fe0 | 2960 | |
252b5132 RH |
2961 | sreloc = bfd_get_section_by_name (dynobj, name); |
2962 | BFD_ASSERT (sreloc != NULL); | |
2963 | } | |
f21f3fe0 | 2964 | |
b34976b6 AM |
2965 | skip = FALSE; |
2966 | relocate = FALSE; | |
f21f3fe0 | 2967 | |
c629eae0 JJ |
2968 | outrel.r_offset = |
2969 | _bfd_elf_section_offset (output_bfd, info, input_section, | |
2970 | rel->r_offset); | |
2971 | if (outrel.r_offset == (bfd_vma) -1) | |
b34976b6 | 2972 | skip = TRUE; |
0bb2d96a | 2973 | else if (outrel.r_offset == (bfd_vma) -2) |
b34976b6 | 2974 | skip = TRUE, relocate = TRUE; |
252b5132 RH |
2975 | outrel.r_offset += (input_section->output_section->vma |
2976 | + input_section->output_offset); | |
f21f3fe0 | 2977 | |
252b5132 | 2978 | if (skip) |
0bb2d96a | 2979 | memset (&outrel, 0, sizeof outrel); |
5e681ec4 PB |
2980 | else if (h != NULL |
2981 | && h->dynindx != -1 | |
7359ea65 | 2982 | && (!info->shared |
5e681ec4 | 2983 | || !info->symbolic |
f5385ebf | 2984 | || !h->def_regular)) |
5e681ec4 | 2985 | outrel.r_info = ELF32_R_INFO (h->dynindx, r_type); |
252b5132 RH |
2986 | else |
2987 | { | |
a16385dc MM |
2988 | int symbol; |
2989 | ||
5e681ec4 PB |
2990 | /* This symbol is local, or marked to become local. */ |
2991 | relocate = TRUE; | |
b7693d02 DJ |
2992 | if (sym_flags == STT_ARM_TFUNC) |
2993 | value |= 1; | |
a16385dc | 2994 | if (globals->symbian_p) |
6366ff1e MM |
2995 | { |
2996 | /* On Symbian OS, the data segment and text segement | |
2997 | can be relocated independently. Therefore, we | |
2998 | must indicate the segment to which this | |
2999 | relocation is relative. The BPABI allows us to | |
3000 | use any symbol in the right segment; we just use | |
3001 | the section symbol as it is convenient. (We | |
3002 | cannot use the symbol given by "h" directly as it | |
3003 | will not appear in the dynamic symbol table.) */ | |
10dbd1f3 NC |
3004 | if (sym_sec) |
3005 | symbol = elf_section_data (sym_sec->output_section)->dynindx; | |
3006 | else | |
3007 | symbol = elf_section_data (input_section->output_section)->dynindx; | |
6366ff1e MM |
3008 | BFD_ASSERT (symbol != 0); |
3009 | } | |
a16385dc MM |
3010 | else |
3011 | /* On SVR4-ish systems, the dynamic loader cannot | |
3012 | relocate the text and data segments independently, | |
3013 | so the symbol does not matter. */ | |
3014 | symbol = 0; | |
3015 | outrel.r_info = ELF32_R_INFO (symbol, R_ARM_RELATIVE); | |
252b5132 | 3016 | } |
f21f3fe0 | 3017 | |
947216bf AM |
3018 | loc = sreloc->contents; |
3019 | loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rel); | |
3020 | bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc); | |
9a5aca8c | 3021 | |
f21f3fe0 | 3022 | /* If this reloc is against an external symbol, we do not want to |
252b5132 | 3023 | fiddle with the addend. Otherwise, we need to include the symbol |
9b485d32 | 3024 | value so that it becomes an addend for the dynamic reloc. */ |
252b5132 RH |
3025 | if (! relocate) |
3026 | return bfd_reloc_ok; | |
9a5aca8c | 3027 | |
f21f3fe0 | 3028 | return _bfd_final_link_relocate (howto, input_bfd, input_section, |
252b5132 RH |
3029 | contents, rel->r_offset, value, |
3030 | (bfd_vma) 0); | |
3031 | } | |
3032 | else switch (r_type) | |
3033 | { | |
dfc5f959 | 3034 | case R_ARM_XPC25: /* Arm BLX instruction. */ |
5b5bb741 PB |
3035 | case R_ARM_CALL: |
3036 | case R_ARM_JUMP24: | |
dfc5f959 | 3037 | case R_ARM_PC24: /* Arm B/BL instruction */ |
7359ea65 | 3038 | case R_ARM_PLT32: |
dfc5f959 | 3039 | if (r_type == R_ARM_XPC25) |
252b5132 | 3040 | { |
dfc5f959 NC |
3041 | /* Check for Arm calling Arm function. */ |
3042 | /* FIXME: Should we translate the instruction into a BL | |
3043 | instruction instead ? */ | |
3044 | if (sym_flags != STT_ARM_TFUNC) | |
d003868e AM |
3045 | (*_bfd_error_handler) |
3046 | (_("\%B: Warning: Arm BLX instruction targets Arm function '%s'."), | |
3047 | input_bfd, | |
3048 | h ? h->root.root.string : "(local)"); | |
dfc5f959 NC |
3049 | } |
3050 | else | |
dfc5f959 NC |
3051 | { |
3052 | /* Check for Arm calling Thumb function. */ | |
3053 | if (sym_flags == STT_ARM_TFUNC) | |
3054 | { | |
57e8b36a NC |
3055 | elf32_arm_to_thumb_stub (info, sym_name, input_bfd, |
3056 | output_bfd, input_section, | |
3057 | hit_data, sym_sec, rel->r_offset, | |
dfc5f959 NC |
3058 | signed_addend, value); |
3059 | return bfd_reloc_ok; | |
3060 | } | |
252b5132 | 3061 | } |
ba96a88f | 3062 | |
dea514f5 PB |
3063 | /* The ARM ELF ABI says that this reloc is computed as: S - P + A |
3064 | where: | |
3065 | S is the address of the symbol in the relocation. | |
3066 | P is address of the instruction being relocated. | |
3067 | A is the addend (extracted from the instruction) in bytes. | |
3068 | ||
3069 | S is held in 'value'. | |
3070 | P is the base address of the section containing the | |
3071 | instruction plus the offset of the reloc into that | |
3072 | section, ie: | |
3073 | (input_section->output_section->vma + | |
3074 | input_section->output_offset + | |
3075 | rel->r_offset). | |
3076 | A is the addend, converted into bytes, ie: | |
3077 | (signed_addend * 4) | |
3078 | ||
3079 | Note: None of these operations have knowledge of the pipeline | |
3080 | size of the processor, thus it is up to the assembler to | |
3081 | encode this information into the addend. */ | |
3082 | value -= (input_section->output_section->vma | |
3083 | + input_section->output_offset); | |
3084 | value -= rel->r_offset; | |
4e7fd91e PB |
3085 | if (globals->use_rel) |
3086 | value += (signed_addend << howto->size); | |
3087 | else | |
3088 | /* RELA addends do not have to be adjusted by howto->size. */ | |
3089 | value += signed_addend; | |
23080146 | 3090 | |
dcb5e6e6 NC |
3091 | signed_addend = value; |
3092 | signed_addend >>= howto->rightshift; | |
9a5aca8c | 3093 | |
59f2c4e7 NC |
3094 | /* It is not an error for an undefined weak reference to be |
3095 | out of range. Any program that branches to such a symbol | |
9a5aca8c AM |
3096 | is going to crash anyway, so there is no point worrying |
3097 | about getting the destination exactly right. */ | |
59f2c4e7 NC |
3098 | if (! h || h->root.type != bfd_link_hash_undefweak) |
3099 | { | |
9b485d32 | 3100 | /* Perform a signed range check. */ |
dcb5e6e6 | 3101 | if ( signed_addend > ((bfd_signed_vma) (howto->dst_mask >> 1)) |
59f2c4e7 NC |
3102 | || signed_addend < - ((bfd_signed_vma) ((howto->dst_mask + 1) >> 1))) |
3103 | return bfd_reloc_overflow; | |
3104 | } | |
9a5aca8c | 3105 | |
dcb5e6e6 NC |
3106 | /* If necessary set the H bit in the BLX instruction. */ |
3107 | if (r_type == R_ARM_XPC25 && ((value & 2) == 2)) | |
3108 | value = (signed_addend & howto->dst_mask) | |
3109 | | (bfd_get_32 (input_bfd, hit_data) & (~ howto->dst_mask)) | |
3110 | | (1 << 24); | |
3111 | else | |
dcb5e6e6 NC |
3112 | value = (signed_addend & howto->dst_mask) |
3113 | | (bfd_get_32 (input_bfd, hit_data) & (~ howto->dst_mask)); | |
252b5132 | 3114 | break; |
f21f3fe0 | 3115 | |
252b5132 RH |
3116 | case R_ARM_ABS32: |
3117 | value += addend; | |
3118 | if (sym_flags == STT_ARM_TFUNC) | |
3119 | value |= 1; | |
3120 | break; | |
f21f3fe0 | 3121 | |
252b5132 RH |
3122 | case R_ARM_REL32: |
3123 | value -= (input_section->output_section->vma | |
62efb346 | 3124 | + input_section->output_offset + rel->r_offset); |
252b5132 RH |
3125 | value += addend; |
3126 | break; | |
eb043451 | 3127 | |
eb043451 PB |
3128 | case R_ARM_PREL31: |
3129 | value -= (input_section->output_section->vma | |
3130 | + input_section->output_offset + rel->r_offset); | |
3131 | value += signed_addend; | |
3132 | if (! h || h->root.type != bfd_link_hash_undefweak) | |
3133 | { | |
3134 | /* Check for overflow */ | |
3135 | if ((value ^ (value >> 1)) & (1 << 30)) | |
3136 | return bfd_reloc_overflow; | |
3137 | } | |
3138 | value &= 0x7fffffff; | |
3139 | value |= (bfd_get_32 (input_bfd, hit_data) & 0x80000000); | |
3140 | if (sym_flags == STT_ARM_TFUNC) | |
3141 | value |= 1; | |
3142 | break; | |
252b5132 | 3143 | } |
f21f3fe0 | 3144 | |
252b5132 RH |
3145 | bfd_put_32 (input_bfd, value, hit_data); |
3146 | return bfd_reloc_ok; | |
3147 | ||
3148 | case R_ARM_ABS8: | |
3149 | value += addend; | |
3150 | if ((long) value > 0x7f || (long) value < -0x80) | |
3151 | return bfd_reloc_overflow; | |
3152 | ||
3153 | bfd_put_8 (input_bfd, value, hit_data); | |
3154 | return bfd_reloc_ok; | |
3155 | ||
3156 | case R_ARM_ABS16: | |
3157 | value += addend; | |
3158 | ||
3159 | if ((long) value > 0x7fff || (long) value < -0x8000) | |
3160 | return bfd_reloc_overflow; | |
3161 | ||
3162 | bfd_put_16 (input_bfd, value, hit_data); | |
3163 | return bfd_reloc_ok; | |
3164 | ||
3165 | case R_ARM_ABS12: | |
3166 | /* Support ldr and str instruction for the arm */ | |
3167 | /* Also thumb b (unconditional branch). ??? Really? */ | |
3168 | value += addend; | |
3169 | ||
3170 | if ((long) value > 0x7ff || (long) value < -0x800) | |
3171 | return bfd_reloc_overflow; | |
3172 | ||
3173 | value |= (bfd_get_32 (input_bfd, hit_data) & 0xfffff000); | |
3174 | bfd_put_32 (input_bfd, value, hit_data); | |
3175 | return bfd_reloc_ok; | |
3176 | ||
3177 | case R_ARM_THM_ABS5: | |
9b485d32 | 3178 | /* Support ldr and str instructions for the thumb. */ |
4e7fd91e PB |
3179 | if (globals->use_rel) |
3180 | { | |
3181 | /* Need to refetch addend. */ | |
3182 | addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask; | |
3183 | /* ??? Need to determine shift amount from operand size. */ | |
3184 | addend >>= howto->rightshift; | |
3185 | } | |
252b5132 RH |
3186 | value += addend; |
3187 | ||
3188 | /* ??? Isn't value unsigned? */ | |
3189 | if ((long) value > 0x1f || (long) value < -0x10) | |
3190 | return bfd_reloc_overflow; | |
3191 | ||
3192 | /* ??? Value needs to be properly shifted into place first. */ | |
3193 | value |= bfd_get_16 (input_bfd, hit_data) & 0xf83f; | |
3194 | bfd_put_16 (input_bfd, value, hit_data); | |
3195 | return bfd_reloc_ok; | |
3196 | ||
dfc5f959 | 3197 | case R_ARM_THM_XPC22: |
c19d1205 | 3198 | case R_ARM_THM_CALL: |
dfc5f959 | 3199 | /* Thumb BL (branch long instruction). */ |
252b5132 | 3200 | { |
b34976b6 AM |
3201 | bfd_vma relocation; |
3202 | bfd_boolean overflow = FALSE; | |
3203 | bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data); | |
3204 | bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2); | |
df212a7e | 3205 | bfd_signed_vma reloc_signed_max = ((1 << (howto->bitsize - 1)) - 1) >> howto->rightshift; |
ba96a88f | 3206 | bfd_signed_vma reloc_signed_min = ~ reloc_signed_max; |
b34976b6 | 3207 | bfd_vma check; |
252b5132 | 3208 | bfd_signed_vma signed_check; |
33bfe774 | 3209 | bfd_boolean thumb_plt_call = FALSE; |
252b5132 | 3210 | |
252b5132 RH |
3211 | /* Need to refetch the addend and squish the two 11 bit pieces |
3212 | together. */ | |
4e7fd91e PB |
3213 | if (globals->use_rel) |
3214 | { | |
3215 | bfd_vma upper = upper_insn & 0x7ff; | |
3216 | bfd_vma lower = lower_insn & 0x7ff; | |
3217 | upper = (upper ^ 0x400) - 0x400; /* Sign extend. */ | |
3218 | addend = (upper << 12) | (lower << 1); | |
3219 | signed_addend = addend; | |
3220 | } | |
cb1afa5c | 3221 | |
dfc5f959 NC |
3222 | if (r_type == R_ARM_THM_XPC22) |
3223 | { | |
3224 | /* Check for Thumb to Thumb call. */ | |
3225 | /* FIXME: Should we translate the instruction into a BL | |
3226 | instruction instead ? */ | |
3227 | if (sym_flags == STT_ARM_TFUNC) | |
d003868e AM |
3228 | (*_bfd_error_handler) |
3229 | (_("%B: Warning: Thumb BLX instruction targets thumb function '%s'."), | |
3230 | input_bfd, | |
3231 | h ? h->root.root.string : "(local)"); | |
dfc5f959 NC |
3232 | } |
3233 | else | |
252b5132 | 3234 | { |
dfc5f959 NC |
3235 | /* If it is not a call to Thumb, assume call to Arm. |
3236 | If it is a call relative to a section name, then it is not a | |
b7693d02 DJ |
3237 | function call at all, but rather a long jump. Calls through |
3238 | the PLT do not require stubs. */ | |
3239 | if (sym_flags != STT_ARM_TFUNC && sym_flags != STT_SECTION | |
3240 | && (h == NULL || splt == NULL | |
3241 | || h->plt.offset == (bfd_vma) -1)) | |
dfc5f959 NC |
3242 | { |
3243 | if (elf32_thumb_to_arm_stub | |
3244 | (info, sym_name, input_bfd, output_bfd, input_section, | |
3245 | hit_data, sym_sec, rel->r_offset, signed_addend, value)) | |
3246 | return bfd_reloc_ok; | |
3247 | else | |
3248 | return bfd_reloc_dangerous; | |
3249 | } | |
252b5132 | 3250 | } |
f21f3fe0 | 3251 | |
b7693d02 DJ |
3252 | /* Handle calls via the PLT. */ |
3253 | if (h != NULL && splt != NULL && h->plt.offset != (bfd_vma) -1) | |
3254 | { | |
3255 | value = (splt->output_section->vma | |
3256 | + splt->output_offset | |
3257 | + h->plt.offset); | |
33bfe774 JB |
3258 | if (globals->use_blx) |
3259 | { | |
3260 | /* If the Thumb BLX instruction is available, convert the | |
3261 | BL to a BLX instruction to call the ARM-mode PLT entry. */ | |
3262 | if ((lower_insn & (0x3 << 11)) == 0x3 << 11) | |
3263 | { | |
3264 | lower_insn = (lower_insn & ~(0x3 << 11)) | 0x1 << 11; | |
3265 | thumb_plt_call = TRUE; | |
3266 | } | |
3267 | } | |
3268 | else | |
3269 | /* Target the Thumb stub before the ARM PLT entry. */ | |
3270 | value -= PLT_THUMB_STUB_SIZE; | |
0945cdfd | 3271 | *unresolved_reloc_p = FALSE; |
b7693d02 DJ |
3272 | } |
3273 | ||
ba96a88f | 3274 | relocation = value + signed_addend; |
f21f3fe0 | 3275 | |
252b5132 | 3276 | relocation -= (input_section->output_section->vma |
ba96a88f NC |
3277 | + input_section->output_offset |
3278 | + rel->r_offset); | |
9a5aca8c | 3279 | |
252b5132 RH |
3280 | check = relocation >> howto->rightshift; |
3281 | ||
3282 | /* If this is a signed value, the rightshift just dropped | |
3283 | leading 1 bits (assuming twos complement). */ | |
3284 | if ((bfd_signed_vma) relocation >= 0) | |
3285 | signed_check = check; | |
3286 | else | |
3287 | signed_check = check | ~((bfd_vma) -1 >> howto->rightshift); | |
3288 | ||
252b5132 | 3289 | /* Assumes two's complement. */ |
ba96a88f | 3290 | if (signed_check > reloc_signed_max || signed_check < reloc_signed_min) |
b34976b6 | 3291 | overflow = TRUE; |
252b5132 | 3292 | |
33bfe774 JB |
3293 | if ((r_type == R_ARM_THM_XPC22 |
3294 | && ((lower_insn & 0x1800) == 0x0800)) | |
3295 | || thumb_plt_call) | |
c62e1cc3 NC |
3296 | /* For a BLX instruction, make sure that the relocation is rounded up |
3297 | to a word boundary. This follows the semantics of the instruction | |
3298 | which specifies that bit 1 of the target address will come from bit | |
3299 | 1 of the base address. */ | |
3300 | relocation = (relocation + 2) & ~ 3; | |
cb1afa5c | 3301 | |
c62e1cc3 NC |
3302 | /* Put RELOCATION back into the insn. */ |
3303 | upper_insn = (upper_insn & ~(bfd_vma) 0x7ff) | ((relocation >> 12) & 0x7ff); | |
3304 | lower_insn = (lower_insn & ~(bfd_vma) 0x7ff) | ((relocation >> 1) & 0x7ff); | |
3305 | ||
252b5132 RH |
3306 | /* Put the relocated value back in the object file: */ |
3307 | bfd_put_16 (input_bfd, upper_insn, hit_data); | |
3308 | bfd_put_16 (input_bfd, lower_insn, hit_data + 2); | |
3309 | ||
3310 | return (overflow ? bfd_reloc_overflow : bfd_reloc_ok); | |
3311 | } | |
3312 | break; | |
3313 | ||
c19d1205 ZW |
3314 | case R_ARM_THM_JUMP24: |
3315 | /* Thumb32 unconditional branch instruction. */ | |
3316 | { | |
3317 | bfd_vma relocation; | |
3318 | bfd_boolean overflow = FALSE; | |
3319 | bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data); | |
3320 | bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2); | |
3321 | bfd_signed_vma reloc_signed_max = ((1 << (howto->bitsize - 1)) - 1) >> howto->rightshift; | |
3322 | bfd_signed_vma reloc_signed_min = ~ reloc_signed_max; | |
3323 | bfd_vma check; | |
3324 | bfd_signed_vma signed_check; | |
3325 | ||
3326 | /* Need to refetch the addend, reconstruct the top three bits, and glue the | |
3327 | two pieces together. */ | |
3328 | if (globals->use_rel) | |
3329 | { | |
3330 | bfd_vma S = (upper_insn & 0x0400) >> 10; | |
3331 | bfd_vma hi = (upper_insn & 0x03ff); | |
3332 | bfd_vma I1 = (lower_insn & 0x2000) >> 13; | |
3333 | bfd_vma I2 = (lower_insn & 0x0800) >> 11; | |
3334 | bfd_vma lo = (lower_insn & 0x07ff); | |
3335 | ||
3336 | I1 = !(I1 ^ S); | |
3337 | I2 = !(I2 ^ S); | |
3338 | S = !S; | |
3339 | ||
3340 | signed_addend = (S << 24) | (I1 << 23) | (I2 << 22) | (hi << 12) | (lo << 1); | |
3341 | signed_addend -= (1 << 24); /* Sign extend. */ | |
3342 | } | |
3343 | ||
3344 | /* ??? Should handle interworking? GCC might someday try to | |
3345 | use this for tail calls. */ | |
3346 | ||
3347 | relocation = value + signed_addend; | |
3348 | relocation -= (input_section->output_section->vma | |
3349 | + input_section->output_offset | |
3350 | + rel->r_offset); | |
3351 | ||
3352 | check = relocation >> howto->rightshift; | |
3353 | ||
3354 | /* If this is a signed value, the rightshift just dropped | |
3355 | leading 1 bits (assuming twos complement). */ | |
3356 | if ((bfd_signed_vma) relocation >= 0) | |
3357 | signed_check = check; | |
3358 | else | |
3359 | signed_check = check | ~((bfd_vma) -1 >> howto->rightshift); | |
3360 | ||
3361 | /* Assumes two's complement. */ | |
3362 | if (signed_check > reloc_signed_max || signed_check < reloc_signed_min) | |
3363 | overflow = TRUE; | |
3364 | ||
3365 | /* Put RELOCATION back into the insn. */ | |
3366 | { | |
3367 | bfd_vma S = (relocation & 0x01000000) >> 24; | |
3368 | bfd_vma I1 = (relocation & 0x00800000) >> 23; | |
3369 | bfd_vma I2 = (relocation & 0x00400000) >> 22; | |
3370 | bfd_vma hi = (relocation & 0x003ff000) >> 12; | |
3371 | bfd_vma lo = (relocation & 0x00000ffe) >> 1; | |
3372 | ||
3373 | I1 = !(I1 ^ S); | |
3374 | I2 = !(I2 ^ S); | |
3375 | ||
3376 | upper_insn = (upper_insn & (bfd_vma) 0xf800) | (S << 10) | hi; | |
3377 | lower_insn = (lower_insn & (bfd_vma) 0xd000) | (I1 << 13) | (I2 << 11) | lo; | |
3378 | } | |
3379 | ||
3380 | /* Put the relocated value back in the object file: */ | |
3381 | bfd_put_16 (input_bfd, upper_insn, hit_data); | |
3382 | bfd_put_16 (input_bfd, lower_insn, hit_data + 2); | |
3383 | ||
3384 | return (overflow ? bfd_reloc_overflow : bfd_reloc_ok); | |
3385 | } | |
3386 | ||
3387 | case R_ARM_THM_JUMP19: | |
3388 | /* Thumb32 conditional branch instruction. */ | |
3389 | { | |
3390 | bfd_vma relocation; | |
3391 | bfd_boolean overflow = FALSE; | |
3392 | bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data); | |
3393 | bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2); | |
3394 | bfd_signed_vma reloc_signed_max = ((1 << (howto->bitsize - 1)) - 1) >> howto->rightshift; | |
3395 | bfd_signed_vma reloc_signed_min = ~ reloc_signed_max; | |
3396 | bfd_vma check; | |
3397 | bfd_signed_vma signed_check; | |
3398 | ||
3399 | /* Need to refetch the addend, reconstruct the top three bits, | |
3400 | and squish the two 11 bit pieces together. */ | |
3401 | if (globals->use_rel) | |
3402 | { | |
3403 | bfd_vma S = (upper_insn & 0x0400) >> 10; | |
3404 | bfd_vma upper = (upper_insn & 0x001f); | |
3405 | bfd_vma J1 = (lower_insn & 0x2000) >> 13; | |
3406 | bfd_vma J2 = (lower_insn & 0x0800) >> 11; | |
3407 | bfd_vma lower = (lower_insn & 0x07ff); | |
3408 | ||
3409 | upper |= J2 << 6; | |
3410 | upper |= J1 << 7; | |
3411 | upper |= ~S << 8; | |
3412 | upper -= 0x0100; /* Sign extend. */ | |
3413 | ||
3414 | addend = (upper << 12) | (lower << 1); | |
3415 | signed_addend = addend; | |
3416 | } | |
3417 | ||
3418 | /* ??? Should handle interworking? GCC might someday try to | |
3419 | use this for tail calls. */ | |
3420 | ||
3421 | relocation = value + signed_addend; | |
3422 | relocation -= (input_section->output_section->vma | |
3423 | + input_section->output_offset | |
3424 | + rel->r_offset); | |
3425 | ||
3426 | check = relocation >> howto->rightshift; | |
3427 | ||
3428 | /* If this is a signed value, the rightshift just dropped | |
3429 | leading 1 bits (assuming twos complement). */ | |
3430 | if ((bfd_signed_vma) relocation >= 0) | |
3431 | signed_check = check; | |
3432 | else | |
3433 | signed_check = check | ~((bfd_vma) -1 >> howto->rightshift); | |
3434 | ||
3435 | /* Assumes two's complement. */ | |
3436 | if (signed_check > reloc_signed_max || signed_check < reloc_signed_min) | |
3437 | overflow = TRUE; | |
3438 | ||
3439 | /* Put RELOCATION back into the insn. */ | |
3440 | { | |
3441 | bfd_vma S = (relocation & 0x00100000) >> 20; | |
3442 | bfd_vma J2 = (relocation & 0x00080000) >> 19; | |
3443 | bfd_vma J1 = (relocation & 0x00040000) >> 18; | |
3444 | bfd_vma hi = (relocation & 0x0003f000) >> 12; | |
3445 | bfd_vma lo = (relocation & 0x00000ffe) >> 1; | |
3446 | ||
3447 | upper_insn = (upper_insn & 0xfb30) | (S << 10) | hi; | |
3448 | lower_insn = (lower_insn & 0xd000) | (J1 << 13) | (J2 << 11) | lo; | |
3449 | } | |
3450 | ||
3451 | /* Put the relocated value back in the object file: */ | |
3452 | bfd_put_16 (input_bfd, upper_insn, hit_data); | |
3453 | bfd_put_16 (input_bfd, lower_insn, hit_data + 2); | |
3454 | ||
3455 | return (overflow ? bfd_reloc_overflow : bfd_reloc_ok); | |
3456 | } | |
3457 | ||
3458 | case R_ARM_THM_JUMP11: | |
3459 | case R_ARM_THM_JUMP8: | |
3460 | case R_ARM_THM_JUMP6: | |
51c5503b NC |
3461 | /* Thumb B (branch) instruction). */ |
3462 | { | |
6cf9e9fe | 3463 | bfd_signed_vma relocation; |
51c5503b NC |
3464 | bfd_signed_vma reloc_signed_max = (1 << (howto->bitsize - 1)) - 1; |
3465 | bfd_signed_vma reloc_signed_min = ~ reloc_signed_max; | |
51c5503b NC |
3466 | bfd_signed_vma signed_check; |
3467 | ||
c19d1205 ZW |
3468 | /* CZB cannot jump backward. */ |
3469 | if (r_type == R_ARM_THM_JUMP6) | |
3470 | reloc_signed_min = 0; | |
3471 | ||
4e7fd91e | 3472 | if (globals->use_rel) |
6cf9e9fe | 3473 | { |
4e7fd91e PB |
3474 | /* Need to refetch addend. */ |
3475 | addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask; | |
3476 | if (addend & ((howto->src_mask + 1) >> 1)) | |
3477 | { | |
3478 | signed_addend = -1; | |
3479 | signed_addend &= ~ howto->src_mask; | |
3480 | signed_addend |= addend; | |
3481 | } | |
3482 | else | |
3483 | signed_addend = addend; | |
3484 | /* The value in the insn has been right shifted. We need to | |
3485 | undo this, so that we can perform the address calculation | |
3486 | in terms of bytes. */ | |
3487 | signed_addend <<= howto->rightshift; | |
6cf9e9fe | 3488 | } |
6cf9e9fe | 3489 | relocation = value + signed_addend; |
51c5503b NC |
3490 | |
3491 | relocation -= (input_section->output_section->vma | |
3492 | + input_section->output_offset | |
3493 | + rel->r_offset); | |
3494 | ||
6cf9e9fe NC |
3495 | relocation >>= howto->rightshift; |
3496 | signed_check = relocation; | |
c19d1205 ZW |
3497 | |
3498 | if (r_type == R_ARM_THM_JUMP6) | |
3499 | relocation = ((relocation & 0x0020) << 4) | ((relocation & 0x001f) << 3); | |
3500 | else | |
3501 | relocation &= howto->dst_mask; | |
51c5503b | 3502 | relocation |= (bfd_get_16 (input_bfd, hit_data) & (~ howto->dst_mask)); |
cedb70c5 | 3503 | |
51c5503b NC |
3504 | bfd_put_16 (input_bfd, relocation, hit_data); |
3505 | ||
3506 | /* Assumes two's complement. */ | |
3507 | if (signed_check > reloc_signed_max || signed_check < reloc_signed_min) | |
3508 | return bfd_reloc_overflow; | |
3509 | ||
3510 | return bfd_reloc_ok; | |
3511 | } | |
cedb70c5 | 3512 | |
8375c36b PB |
3513 | case R_ARM_ALU_PCREL7_0: |
3514 | case R_ARM_ALU_PCREL15_8: | |
3515 | case R_ARM_ALU_PCREL23_15: | |
3516 | { | |
3517 | bfd_vma insn; | |
3518 | bfd_vma relocation; | |
3519 | ||
3520 | insn = bfd_get_32 (input_bfd, hit_data); | |
4e7fd91e PB |
3521 | if (globals->use_rel) |
3522 | { | |
3523 | /* Extract the addend. */ | |
3524 | addend = (insn & 0xff) << ((insn & 0xf00) >> 7); | |
3525 | signed_addend = addend; | |
3526 | } | |
8375c36b PB |
3527 | relocation = value + signed_addend; |
3528 | ||
3529 | relocation -= (input_section->output_section->vma | |
3530 | + input_section->output_offset | |
3531 | + rel->r_offset); | |
3532 | insn = (insn & ~0xfff) | |
3533 | | ((howto->bitpos << 7) & 0xf00) | |
3534 | | ((relocation >> howto->bitpos) & 0xff); | |
3535 | bfd_put_32 (input_bfd, value, hit_data); | |
3536 | } | |
3537 | return bfd_reloc_ok; | |
3538 | ||
252b5132 RH |
3539 | case R_ARM_GNU_VTINHERIT: |
3540 | case R_ARM_GNU_VTENTRY: | |
3541 | return bfd_reloc_ok; | |
3542 | ||
c19d1205 | 3543 | case R_ARM_GOTOFF32: |
252b5132 RH |
3544 | /* Relocation is relative to the start of the |
3545 | global offset table. */ | |
3546 | ||
3547 | BFD_ASSERT (sgot != NULL); | |
3548 | if (sgot == NULL) | |
3549 | return bfd_reloc_notsupported; | |
9a5aca8c | 3550 | |
cedb70c5 | 3551 | /* If we are addressing a Thumb function, we need to adjust the |
ee29b9fb RE |
3552 | address by one, so that attempts to call the function pointer will |
3553 | correctly interpret it as Thumb code. */ | |
3554 | if (sym_flags == STT_ARM_TFUNC) | |
3555 | value += 1; | |
3556 | ||
252b5132 RH |
3557 | /* Note that sgot->output_offset is not involved in this |
3558 | calculation. We always want the start of .got. If we | |
3559 | define _GLOBAL_OFFSET_TABLE in a different way, as is | |
3560 | permitted by the ABI, we might have to change this | |
9b485d32 | 3561 | calculation. */ |
252b5132 | 3562 | value -= sgot->output_section->vma; |
f21f3fe0 | 3563 | return _bfd_final_link_relocate (howto, input_bfd, input_section, |
99e4ae17 AJ |
3564 | contents, rel->r_offset, value, |
3565 | (bfd_vma) 0); | |
252b5132 RH |
3566 | |
3567 | case R_ARM_GOTPC: | |
a7c10850 | 3568 | /* Use global offset table as symbol value. */ |
252b5132 | 3569 | BFD_ASSERT (sgot != NULL); |
f21f3fe0 | 3570 | |
252b5132 RH |
3571 | if (sgot == NULL) |
3572 | return bfd_reloc_notsupported; | |
3573 | ||
0945cdfd | 3574 | *unresolved_reloc_p = FALSE; |
252b5132 | 3575 | value = sgot->output_section->vma; |
f21f3fe0 | 3576 | return _bfd_final_link_relocate (howto, input_bfd, input_section, |
99e4ae17 AJ |
3577 | contents, rel->r_offset, value, |
3578 | (bfd_vma) 0); | |
f21f3fe0 | 3579 | |
252b5132 | 3580 | case R_ARM_GOT32: |
eb043451 | 3581 | case R_ARM_GOT_PREL: |
252b5132 | 3582 | /* Relocation is to the entry for this symbol in the |
9b485d32 | 3583 | global offset table. */ |
252b5132 RH |
3584 | if (sgot == NULL) |
3585 | return bfd_reloc_notsupported; | |
f21f3fe0 | 3586 | |
252b5132 RH |
3587 | if (h != NULL) |
3588 | { | |
3589 | bfd_vma off; | |
5e681ec4 | 3590 | bfd_boolean dyn; |
f21f3fe0 | 3591 | |
252b5132 RH |
3592 | off = h->got.offset; |
3593 | BFD_ASSERT (off != (bfd_vma) -1); | |
5e681ec4 | 3594 | dyn = globals->root.dynamic_sections_created; |
f21f3fe0 | 3595 | |
5e681ec4 | 3596 | if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) |
50d6c878 | 3597 | || (info->shared |
5e681ec4 PB |
3598 | && SYMBOL_REFERENCES_LOCAL (info, h)) |
3599 | || (ELF_ST_VISIBILITY (h->other) | |
3600 | && h->root.type == bfd_link_hash_undefweak)) | |
252b5132 RH |
3601 | { |
3602 | /* This is actually a static link, or it is a -Bsymbolic link | |
3603 | and the symbol is defined locally. We must initialize this | |
3604 | entry in the global offset table. Since the offset must | |
3605 | always be a multiple of 4, we use the least significant bit | |
3606 | to record whether we have initialized it already. | |
f21f3fe0 | 3607 | |
252b5132 | 3608 | When doing a dynamic link, we create a .rel.got relocation |
f21f3fe0 | 3609 | entry to initialize the value. This is done in the |
9b485d32 | 3610 | finish_dynamic_symbol routine. */ |
252b5132 RH |
3611 | if ((off & 1) != 0) |
3612 | off &= ~1; | |
3613 | else | |
3614 | { | |
ee29b9fb RE |
3615 | /* If we are addressing a Thumb function, we need to |
3616 | adjust the address by one, so that attempts to | |
3617 | call the function pointer will correctly | |
3618 | interpret it as Thumb code. */ | |
3619 | if (sym_flags == STT_ARM_TFUNC) | |
3620 | value |= 1; | |
3621 | ||
252b5132 RH |
3622 | bfd_put_32 (output_bfd, value, sgot->contents + off); |
3623 | h->got.offset |= 1; | |
3624 | } | |
3625 | } | |
0945cdfd DJ |
3626 | else |
3627 | *unresolved_reloc_p = FALSE; | |
f21f3fe0 | 3628 | |
252b5132 RH |
3629 | value = sgot->output_offset + off; |
3630 | } | |
3631 | else | |
3632 | { | |
3633 | bfd_vma off; | |
f21f3fe0 | 3634 | |
252b5132 RH |
3635 | BFD_ASSERT (local_got_offsets != NULL && |
3636 | local_got_offsets[r_symndx] != (bfd_vma) -1); | |
f21f3fe0 | 3637 | |
252b5132 | 3638 | off = local_got_offsets[r_symndx]; |
f21f3fe0 | 3639 | |
252b5132 RH |
3640 | /* The offset must always be a multiple of 4. We use the |
3641 | least significant bit to record whether we have already | |
9b485d32 | 3642 | generated the necessary reloc. */ |
252b5132 RH |
3643 | if ((off & 1) != 0) |
3644 | off &= ~1; | |
3645 | else | |
3646 | { | |
b7693d02 DJ |
3647 | /* If we are addressing a Thumb function, we need to |
3648 | adjust the address by one, so that attempts to | |
3649 | call the function pointer will correctly | |
3650 | interpret it as Thumb code. */ | |
3651 | if (sym_flags == STT_ARM_TFUNC) | |
3652 | value |= 1; | |
3653 | ||
252b5132 | 3654 | bfd_put_32 (output_bfd, value, sgot->contents + off); |
f21f3fe0 | 3655 | |
252b5132 RH |
3656 | if (info->shared) |
3657 | { | |
3658 | asection * srelgot; | |
947216bf AM |
3659 | Elf_Internal_Rela outrel; |
3660 | bfd_byte *loc; | |
f21f3fe0 | 3661 | |
252b5132 RH |
3662 | srelgot = bfd_get_section_by_name (dynobj, ".rel.got"); |
3663 | BFD_ASSERT (srelgot != NULL); | |
f21f3fe0 | 3664 | |
252b5132 | 3665 | outrel.r_offset = (sgot->output_section->vma |
f21f3fe0 | 3666 | + sgot->output_offset |
252b5132 RH |
3667 | + off); |
3668 | outrel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE); | |
947216bf AM |
3669 | loc = srelgot->contents; |
3670 | loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rel); | |
3671 | bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc); | |
252b5132 | 3672 | } |
f21f3fe0 | 3673 | |
252b5132 RH |
3674 | local_got_offsets[r_symndx] |= 1; |
3675 | } | |
f21f3fe0 | 3676 | |
252b5132 RH |
3677 | value = sgot->output_offset + off; |
3678 | } | |
eb043451 PB |
3679 | if (r_type != R_ARM_GOT32) |
3680 | value += sgot->output_section->vma; | |
9a5aca8c | 3681 | |
f21f3fe0 | 3682 | return _bfd_final_link_relocate (howto, input_bfd, input_section, |
99e4ae17 AJ |
3683 | contents, rel->r_offset, value, |
3684 | (bfd_vma) 0); | |
f21f3fe0 | 3685 | |
ba93b8ac DJ |
3686 | case R_ARM_TLS_LDO32: |
3687 | value = value - dtpoff_base (info); | |
3688 | ||
3689 | return _bfd_final_link_relocate (howto, input_bfd, input_section, | |
3690 | contents, rel->r_offset, value, (bfd_vma) 0); | |
3691 | ||
3692 | case R_ARM_TLS_LDM32: | |
3693 | { | |
3694 | bfd_vma off; | |
3695 | ||
3696 | if (globals->sgot == NULL) | |
3697 | abort (); | |
3698 | ||
3699 | off = globals->tls_ldm_got.offset; | |
3700 | ||
3701 | if ((off & 1) != 0) | |
3702 | off &= ~1; | |
3703 | else | |
3704 | { | |
3705 | /* If we don't know the module number, create a relocation | |
3706 | for it. */ | |
3707 | if (info->shared) | |
3708 | { | |
3709 | Elf_Internal_Rela outrel; | |
3710 | bfd_byte *loc; | |
3711 | ||
3712 | if (globals->srelgot == NULL) | |
3713 | abort (); | |
3714 | ||
3715 | outrel.r_offset = (globals->sgot->output_section->vma | |
3716 | + globals->sgot->output_offset + off); | |
3717 | outrel.r_info = ELF32_R_INFO (0, R_ARM_TLS_DTPMOD32); | |
3718 | ||
3719 | bfd_put_32 (output_bfd, 0, globals->sgot->contents + off); | |
3720 | ||
3721 | loc = globals->srelgot->contents; | |
3722 | loc += globals->srelgot->reloc_count++ * sizeof (Elf32_External_Rel); | |
3723 | bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc); | |
3724 | } | |
3725 | else | |
3726 | bfd_put_32 (output_bfd, 1, globals->sgot->contents + off); | |
3727 | ||
3728 | globals->tls_ldm_got.offset |= 1; | |
3729 | } | |
3730 | ||
3731 | value = globals->sgot->output_section->vma + globals->sgot->output_offset + off | |
3732 | - (input_section->output_section->vma + input_section->output_offset + rel->r_offset); | |
3733 | ||
3734 | return _bfd_final_link_relocate (howto, input_bfd, input_section, | |
3735 | contents, rel->r_offset, value, | |
3736 | (bfd_vma) 0); | |
3737 | } | |
3738 | ||
3739 | case R_ARM_TLS_GD32: | |
3740 | case R_ARM_TLS_IE32: | |
3741 | { | |
3742 | bfd_vma off; | |
3743 | int indx; | |
3744 | char tls_type; | |
3745 | ||
3746 | if (globals->sgot == NULL) | |
3747 | abort (); | |
3748 | ||
3749 | indx = 0; | |
3750 | if (h != NULL) | |
3751 | { | |
3752 | bfd_boolean dyn; | |
3753 | dyn = globals->root.dynamic_sections_created; | |
3754 | if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) | |
3755 | && (!info->shared | |
3756 | || !SYMBOL_REFERENCES_LOCAL (info, h))) | |
3757 | { | |
3758 | *unresolved_reloc_p = FALSE; | |
3759 | indx = h->dynindx; | |
3760 | } | |
3761 | off = h->got.offset; | |
3762 | tls_type = ((struct elf32_arm_link_hash_entry *) h)->tls_type; | |
3763 | } | |
3764 | else | |
3765 | { | |
3766 | if (local_got_offsets == NULL) | |
3767 | abort (); | |
3768 | off = local_got_offsets[r_symndx]; | |
3769 | tls_type = elf32_arm_local_got_tls_type (input_bfd)[r_symndx]; | |
3770 | } | |
3771 | ||
3772 | if (tls_type == GOT_UNKNOWN) | |
3773 | abort (); | |
3774 | ||
3775 | if ((off & 1) != 0) | |
3776 | off &= ~1; | |
3777 | else | |
3778 | { | |
3779 | bfd_boolean need_relocs = FALSE; | |
3780 | Elf_Internal_Rela outrel; | |
3781 | bfd_byte *loc = NULL; | |
3782 | int cur_off = off; | |
3783 | ||
3784 | /* The GOT entries have not been initialized yet. Do it | |
3785 | now, and emit any relocations. If both an IE GOT and a | |
3786 | GD GOT are necessary, we emit the GD first. */ | |
3787 | ||
3788 | if ((info->shared || indx != 0) | |
3789 | && (h == NULL | |
3790 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
3791 | || h->root.type != bfd_link_hash_undefweak)) | |
3792 | { | |
3793 | need_relocs = TRUE; | |
3794 | if (globals->srelgot == NULL) | |
3795 | abort (); | |
3796 | loc = globals->srelgot->contents; | |
3797 | loc += globals->srelgot->reloc_count * sizeof (Elf32_External_Rel); | |
3798 | } | |
3799 | ||
3800 | if (tls_type & GOT_TLS_GD) | |
3801 | { | |
3802 | if (need_relocs) | |
3803 | { | |
3804 | outrel.r_offset = (globals->sgot->output_section->vma | |
3805 | + globals->sgot->output_offset + cur_off); | |
3806 | outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_DTPMOD32); | |
3807 | bfd_put_32 (output_bfd, 0, globals->sgot->contents + cur_off); | |
3808 | ||
3809 | bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc); | |
3810 | globals->srelgot->reloc_count++; | |
3811 | loc += sizeof (Elf32_External_Rel); | |
3812 | ||
3813 | if (indx == 0) | |
3814 | bfd_put_32 (output_bfd, value - dtpoff_base (info), | |
3815 | globals->sgot->contents + cur_off + 4); | |
3816 | else | |
3817 | { | |
3818 | bfd_put_32 (output_bfd, 0, | |
3819 | globals->sgot->contents + cur_off + 4); | |
3820 | ||
3821 | outrel.r_info = ELF32_R_INFO (indx, | |
3822 | R_ARM_TLS_DTPOFF32); | |
3823 | outrel.r_offset += 4; | |
3824 | bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc); | |
3825 | globals->srelgot->reloc_count++; | |
3826 | loc += sizeof (Elf32_External_Rel); | |
3827 | } | |
3828 | } | |
3829 | else | |
3830 | { | |
3831 | /* If we are not emitting relocations for a | |
3832 | general dynamic reference, then we must be in a | |
3833 | static link or an executable link with the | |
3834 | symbol binding locally. Mark it as belonging | |
3835 | to module 1, the executable. */ | |
3836 | bfd_put_32 (output_bfd, 1, | |
3837 | globals->sgot->contents + cur_off); | |
3838 | bfd_put_32 (output_bfd, value - dtpoff_base (info), | |
3839 | globals->sgot->contents + cur_off + 4); | |
3840 | } | |
3841 | ||
3842 | cur_off += 8; | |
3843 | } | |
3844 | ||
3845 | if (tls_type & GOT_TLS_IE) | |
3846 | { | |
3847 | if (need_relocs) | |
3848 | { | |
3849 | outrel.r_offset = (globals->sgot->output_section->vma | |
3850 | + globals->sgot->output_offset | |
3851 | + cur_off); | |
3852 | outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_TPOFF32); | |
3853 | ||
3854 | if (indx == 0) | |
3855 | bfd_put_32 (output_bfd, value - dtpoff_base (info), | |
3856 | globals->sgot->contents + cur_off); | |
3857 | else | |
3858 | bfd_put_32 (output_bfd, 0, | |
3859 | globals->sgot->contents + cur_off); | |
3860 | ||
3861 | bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc); | |
3862 | globals->srelgot->reloc_count++; | |
3863 | loc += sizeof (Elf32_External_Rel); | |
3864 | } | |
3865 | else | |
3866 | bfd_put_32 (output_bfd, tpoff (info, value), | |
3867 | globals->sgot->contents + cur_off); | |
3868 | cur_off += 4; | |
3869 | } | |
3870 | ||
3871 | if (h != NULL) | |
3872 | h->got.offset |= 1; | |
3873 | else | |
3874 | local_got_offsets[r_symndx] |= 1; | |
3875 | } | |
3876 | ||
3877 | if ((tls_type & GOT_TLS_GD) && r_type != R_ARM_TLS_GD32) | |
3878 | off += 8; | |
3879 | value = globals->sgot->output_section->vma + globals->sgot->output_offset + off | |
3880 | - (input_section->output_section->vma + input_section->output_offset + rel->r_offset); | |
3881 | ||
3882 | return _bfd_final_link_relocate (howto, input_bfd, input_section, | |
3883 | contents, rel->r_offset, value, | |
3884 | (bfd_vma) 0); | |
3885 | } | |
3886 | ||
3887 | case R_ARM_TLS_LE32: | |
3888 | if (info->shared) | |
3889 | { | |
3890 | (*_bfd_error_handler) | |
3891 | (_("%B(%A+0x%lx): R_ARM_TLS_LE32 relocation not permitted in shared object"), | |
3892 | input_bfd, input_section, | |
3893 | (long) rel->r_offset, howto->name); | |
3894 | return FALSE; | |
3895 | } | |
3896 | else | |
3897 | value = tpoff (info, value); | |
3898 | ||
3899 | return _bfd_final_link_relocate (howto, input_bfd, input_section, | |
3900 | contents, rel->r_offset, value, (bfd_vma) 0); | |
3901 | ||
319850b4 JB |
3902 | case R_ARM_V4BX: |
3903 | if (globals->fix_v4bx) | |
3904 | { | |
3905 | bfd_vma insn = bfd_get_32 (input_bfd, hit_data); | |
3906 | ||
3907 | /* Ensure that we have a BX instruction. */ | |
3908 | BFD_ASSERT ((insn & 0x0ffffff0) == 0x012fff10); | |
3909 | ||
3910 | /* Preserve Rm (lowest four bits) and the condition code | |
3911 | (highest four bits). Other bits encode MOV PC,Rm. */ | |
3912 | insn = (insn & 0xf000000f) | 0x01a0f000; | |
3913 | ||
3914 | bfd_put_32 (input_bfd, insn, hit_data); | |
3915 | } | |
3916 | return bfd_reloc_ok; | |
3917 | ||
252b5132 RH |
3918 | default: |
3919 | return bfd_reloc_notsupported; | |
3920 | } | |
3921 | } | |
3922 | ||
98c1d4aa NC |
3923 | /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */ |
3924 | static void | |
57e8b36a NC |
3925 | arm_add_to_rel (bfd * abfd, |
3926 | bfd_byte * address, | |
3927 | reloc_howto_type * howto, | |
3928 | bfd_signed_vma increment) | |
98c1d4aa | 3929 | { |
98c1d4aa NC |
3930 | bfd_signed_vma addend; |
3931 | ||
c19d1205 | 3932 | if (howto->type == R_ARM_THM_CALL) |
98c1d4aa | 3933 | { |
9a5aca8c AM |
3934 | int upper_insn, lower_insn; |
3935 | int upper, lower; | |
98c1d4aa | 3936 | |
9a5aca8c AM |
3937 | upper_insn = bfd_get_16 (abfd, address); |
3938 | lower_insn = bfd_get_16 (abfd, address + 2); | |
3939 | upper = upper_insn & 0x7ff; | |
3940 | lower = lower_insn & 0x7ff; | |
3941 | ||
3942 | addend = (upper << 12) | (lower << 1); | |
ddda4409 | 3943 | addend += increment; |
9a5aca8c | 3944 | addend >>= 1; |
98c1d4aa | 3945 | |
9a5aca8c AM |
3946 | upper_insn = (upper_insn & 0xf800) | ((addend >> 11) & 0x7ff); |
3947 | lower_insn = (lower_insn & 0xf800) | (addend & 0x7ff); | |
3948 | ||
dc810e39 AM |
3949 | bfd_put_16 (abfd, (bfd_vma) upper_insn, address); |
3950 | bfd_put_16 (abfd, (bfd_vma) lower_insn, address + 2); | |
9a5aca8c AM |
3951 | } |
3952 | else | |
3953 | { | |
3954 | bfd_vma contents; | |
3955 | ||
3956 | contents = bfd_get_32 (abfd, address); | |
3957 | ||
3958 | /* Get the (signed) value from the instruction. */ | |
3959 | addend = contents & howto->src_mask; | |
3960 | if (addend & ((howto->src_mask + 1) >> 1)) | |
3961 | { | |
3962 | bfd_signed_vma mask; | |
3963 | ||
3964 | mask = -1; | |
3965 | mask &= ~ howto->src_mask; | |
3966 | addend |= mask; | |
3967 | } | |
3968 | ||
3969 | /* Add in the increment, (which is a byte value). */ | |
3970 | switch (howto->type) | |
3971 | { | |
3972 | default: | |
3973 | addend += increment; | |
3974 | break; | |
3975 | ||
3976 | case R_ARM_PC24: | |
c6596c5e | 3977 | case R_ARM_PLT32: |
5b5bb741 PB |
3978 | case R_ARM_CALL: |
3979 | case R_ARM_JUMP24: | |
9a5aca8c | 3980 | addend <<= howto->size; |
dc810e39 | 3981 | addend += increment; |
9a5aca8c AM |
3982 | |
3983 | /* Should we check for overflow here ? */ | |
3984 | ||
3985 | /* Drop any undesired bits. */ | |
3986 | addend >>= howto->rightshift; | |
3987 | break; | |
3988 | } | |
3989 | ||
3990 | contents = (contents & ~ howto->dst_mask) | (addend & howto->dst_mask); | |
3991 | ||
3992 | bfd_put_32 (abfd, contents, address); | |
ddda4409 | 3993 | } |
98c1d4aa | 3994 | } |
252b5132 | 3995 | |
ba93b8ac DJ |
3996 | #define IS_ARM_TLS_RELOC(R_TYPE) \ |
3997 | ((R_TYPE) == R_ARM_TLS_GD32 \ | |
3998 | || (R_TYPE) == R_ARM_TLS_LDO32 \ | |
3999 | || (R_TYPE) == R_ARM_TLS_LDM32 \ | |
4000 | || (R_TYPE) == R_ARM_TLS_DTPOFF32 \ | |
4001 | || (R_TYPE) == R_ARM_TLS_DTPMOD32 \ | |
4002 | || (R_TYPE) == R_ARM_TLS_TPOFF32 \ | |
4003 | || (R_TYPE) == R_ARM_TLS_LE32 \ | |
4004 | || (R_TYPE) == R_ARM_TLS_IE32) | |
4005 | ||
252b5132 | 4006 | /* Relocate an ARM ELF section. */ |
b34976b6 | 4007 | static bfd_boolean |
57e8b36a NC |
4008 | elf32_arm_relocate_section (bfd * output_bfd, |
4009 | struct bfd_link_info * info, | |
4010 | bfd * input_bfd, | |
4011 | asection * input_section, | |
4012 | bfd_byte * contents, | |
4013 | Elf_Internal_Rela * relocs, | |
4014 | Elf_Internal_Sym * local_syms, | |
4015 | asection ** local_sections) | |
252b5132 | 4016 | { |
b34976b6 AM |
4017 | Elf_Internal_Shdr *symtab_hdr; |
4018 | struct elf_link_hash_entry **sym_hashes; | |
4019 | Elf_Internal_Rela *rel; | |
4020 | Elf_Internal_Rela *relend; | |
4021 | const char *name; | |
b32d3aa2 | 4022 | struct elf32_arm_link_hash_table * globals; |
252b5132 | 4023 | |
4e7fd91e PB |
4024 | globals = elf32_arm_hash_table (info); |
4025 | if (info->relocatable && !globals->use_rel) | |
b34976b6 | 4026 | return TRUE; |
b491616a | 4027 | |
252b5132 RH |
4028 | symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr; |
4029 | sym_hashes = elf_sym_hashes (input_bfd); | |
4030 | ||
4031 | rel = relocs; | |
4032 | relend = relocs + input_section->reloc_count; | |
4033 | for (; rel < relend; rel++) | |
4034 | { | |
ba96a88f NC |
4035 | int r_type; |
4036 | reloc_howto_type * howto; | |
4037 | unsigned long r_symndx; | |
4038 | Elf_Internal_Sym * sym; | |
4039 | asection * sec; | |
252b5132 | 4040 | struct elf_link_hash_entry * h; |
ba96a88f NC |
4041 | bfd_vma relocation; |
4042 | bfd_reloc_status_type r; | |
4043 | arelent bfd_reloc; | |
ba93b8ac | 4044 | char sym_type; |
0945cdfd | 4045 | bfd_boolean unresolved_reloc = FALSE; |
f21f3fe0 | 4046 | |
252b5132 | 4047 | r_symndx = ELF32_R_SYM (rel->r_info); |
ba96a88f | 4048 | r_type = ELF32_R_TYPE (rel->r_info); |
b32d3aa2 | 4049 | r_type = arm_real_reloc_type (globals, r_type); |
252b5132 | 4050 | |
ba96a88f NC |
4051 | if ( r_type == R_ARM_GNU_VTENTRY |
4052 | || r_type == R_ARM_GNU_VTINHERIT) | |
252b5132 RH |
4053 | continue; |
4054 | ||
b32d3aa2 | 4055 | bfd_reloc.howto = elf32_arm_howto_from_type (r_type); |
ba96a88f | 4056 | howto = bfd_reloc.howto; |
252b5132 | 4057 | |
4e7fd91e | 4058 | if (info->relocatable && globals->use_rel) |
252b5132 | 4059 | { |
1049f94e | 4060 | /* This is a relocatable link. We don't have to change |
252b5132 RH |
4061 | anything, unless the reloc is against a section symbol, |
4062 | in which case we have to adjust according to where the | |
4063 | section symbol winds up in the output section. */ | |
4064 | if (r_symndx < symtab_hdr->sh_info) | |
4065 | { | |
4066 | sym = local_syms + r_symndx; | |
4067 | if (ELF_ST_TYPE (sym->st_info) == STT_SECTION) | |
4068 | { | |
4069 | sec = local_sections[r_symndx]; | |
98c1d4aa | 4070 | arm_add_to_rel (input_bfd, contents + rel->r_offset, |
dc810e39 AM |
4071 | howto, |
4072 | (bfd_signed_vma) (sec->output_offset | |
4073 | + sym->st_value)); | |
252b5132 RH |
4074 | } |
4075 | } | |
4076 | ||
4077 | continue; | |
4078 | } | |
4079 | ||
4080 | /* This is a final link. */ | |
4081 | h = NULL; | |
4082 | sym = NULL; | |
4083 | sec = NULL; | |
9b485d32 | 4084 | |
252b5132 RH |
4085 | if (r_symndx < symtab_hdr->sh_info) |
4086 | { | |
4087 | sym = local_syms + r_symndx; | |
ba93b8ac | 4088 | sym_type = ELF32_ST_TYPE (sym->st_info); |
252b5132 | 4089 | sec = local_sections[r_symndx]; |
4e7fd91e | 4090 | if (globals->use_rel) |
f8df10f4 | 4091 | { |
4e7fd91e PB |
4092 | relocation = (sec->output_section->vma |
4093 | + sec->output_offset | |
4094 | + sym->st_value); | |
4095 | if ((sec->flags & SEC_MERGE) | |
4096 | && ELF_ST_TYPE (sym->st_info) == STT_SECTION) | |
f8df10f4 | 4097 | { |
4e7fd91e PB |
4098 | asection *msec; |
4099 | bfd_vma addend, value; | |
4100 | ||
4101 | if (howto->rightshift) | |
4102 | { | |
4103 | (*_bfd_error_handler) | |
4104 | (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"), | |
4105 | input_bfd, input_section, | |
4106 | (long) rel->r_offset, howto->name); | |
4107 | return FALSE; | |
4108 | } | |
f8df10f4 | 4109 | |
4e7fd91e | 4110 | value = bfd_get_32 (input_bfd, contents + rel->r_offset); |
f8df10f4 | 4111 | |
4e7fd91e PB |
4112 | /* Get the (signed) value from the instruction. */ |
4113 | addend = value & howto->src_mask; | |
4114 | if (addend & ((howto->src_mask + 1) >> 1)) | |
4115 | { | |
4116 | bfd_signed_vma mask; | |
f8df10f4 | 4117 | |
4e7fd91e PB |
4118 | mask = -1; |
4119 | mask &= ~ howto->src_mask; | |
4120 | addend |= mask; | |
4121 | } | |
4122 | msec = sec; | |
4123 | addend = | |
4124 | _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend) | |
4125 | - relocation; | |
4126 | addend += msec->output_section->vma + msec->output_offset; | |
4127 | value = (value & ~ howto->dst_mask) | (addend & howto->dst_mask); | |
4128 | bfd_put_32 (input_bfd, value, contents + rel->r_offset); | |
f8df10f4 | 4129 | } |
f8df10f4 | 4130 | } |
4e7fd91e PB |
4131 | else |
4132 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); | |
252b5132 RH |
4133 | } |
4134 | else | |
4135 | { | |
560e09e9 | 4136 | bfd_boolean warned; |
560e09e9 | 4137 | |
b2a8e766 AM |
4138 | RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, |
4139 | r_symndx, symtab_hdr, sym_hashes, | |
4140 | h, sec, relocation, | |
4141 | unresolved_reloc, warned); | |
ba93b8ac DJ |
4142 | |
4143 | sym_type = h->type; | |
252b5132 RH |
4144 | } |
4145 | ||
4146 | if (h != NULL) | |
4147 | name = h->root.root.string; | |
4148 | else | |
4149 | { | |
4150 | name = (bfd_elf_string_from_elf_section | |
4151 | (input_bfd, symtab_hdr->sh_link, sym->st_name)); | |
4152 | if (name == NULL || *name == '\0') | |
4153 | name = bfd_section_name (input_bfd, sec); | |
4154 | } | |
f21f3fe0 | 4155 | |
ba93b8ac DJ |
4156 | if (r_symndx != 0 |
4157 | && r_type != R_ARM_NONE | |
4158 | && (h == NULL | |
4159 | || h->root.type == bfd_link_hash_defined | |
4160 | || h->root.type == bfd_link_hash_defweak) | |
4161 | && IS_ARM_TLS_RELOC (r_type) != (sym_type == STT_TLS)) | |
4162 | { | |
4163 | (*_bfd_error_handler) | |
4164 | ((sym_type == STT_TLS | |
4165 | ? _("%B(%A+0x%lx): %s used with TLS symbol %s") | |
4166 | : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")), | |
4167 | input_bfd, | |
4168 | input_section, | |
4169 | (long) rel->r_offset, | |
4170 | howto->name, | |
4171 | name); | |
4172 | } | |
4173 | ||
252b5132 RH |
4174 | r = elf32_arm_final_link_relocate (howto, input_bfd, output_bfd, |
4175 | input_section, contents, rel, | |
4176 | relocation, info, sec, name, | |
4177 | (h ? ELF_ST_TYPE (h->type) : | |
0945cdfd DJ |
4178 | ELF_ST_TYPE (sym->st_info)), h, |
4179 | &unresolved_reloc); | |
4180 | ||
4181 | /* Dynamic relocs are not propagated for SEC_DEBUGGING sections | |
4182 | because such sections are not SEC_ALLOC and thus ld.so will | |
4183 | not process them. */ | |
4184 | if (unresolved_reloc | |
4185 | && !((input_section->flags & SEC_DEBUGGING) != 0 | |
4186 | && h->def_dynamic)) | |
4187 | { | |
4188 | (*_bfd_error_handler) | |
4189 | (_("%B(%A+0x%lx): warning: unresolvable relocation %d against symbol `%s'"), | |
4190 | input_bfd, input_section, (long) rel->r_offset, | |
4191 | r_type, h->root.root.string); | |
4192 | return FALSE; | |
4193 | } | |
252b5132 RH |
4194 | |
4195 | if (r != bfd_reloc_ok) | |
4196 | { | |
4197 | const char * msg = (const char *) 0; | |
4198 | ||
4199 | switch (r) | |
4200 | { | |
4201 | case bfd_reloc_overflow: | |
cf919dfd PB |
4202 | /* If the overflowing reloc was to an undefined symbol, |
4203 | we have already printed one error message and there | |
4204 | is no point complaining again. */ | |
4205 | if ((! h || | |
4206 | h->root.type != bfd_link_hash_undefined) | |
4207 | && (!((*info->callbacks->reloc_overflow) | |
dfeffb9f L |
4208 | (info, (h ? &h->root : NULL), name, howto->name, |
4209 | (bfd_vma) 0, input_bfd, input_section, | |
4210 | rel->r_offset)))) | |
b34976b6 | 4211 | return FALSE; |
252b5132 RH |
4212 | break; |
4213 | ||
4214 | case bfd_reloc_undefined: | |
4215 | if (!((*info->callbacks->undefined_symbol) | |
4216 | (info, name, input_bfd, input_section, | |
b34976b6 AM |
4217 | rel->r_offset, TRUE))) |
4218 | return FALSE; | |
252b5132 RH |
4219 | break; |
4220 | ||
4221 | case bfd_reloc_outofrange: | |
9b485d32 | 4222 | msg = _("internal error: out of range error"); |
252b5132 RH |
4223 | goto common_error; |
4224 | ||
4225 | case bfd_reloc_notsupported: | |
9b485d32 | 4226 | msg = _("internal error: unsupported relocation error"); |
252b5132 RH |
4227 | goto common_error; |
4228 | ||
4229 | case bfd_reloc_dangerous: | |
9b485d32 | 4230 | msg = _("internal error: dangerous error"); |
252b5132 RH |
4231 | goto common_error; |
4232 | ||
4233 | default: | |
9b485d32 | 4234 | msg = _("internal error: unknown error"); |
252b5132 RH |
4235 | /* fall through */ |
4236 | ||
4237 | common_error: | |
4238 | if (!((*info->callbacks->warning) | |
4239 | (info, msg, name, input_bfd, input_section, | |
4240 | rel->r_offset))) | |
b34976b6 | 4241 | return FALSE; |
252b5132 RH |
4242 | break; |
4243 | } | |
4244 | } | |
4245 | } | |
4246 | ||
b34976b6 | 4247 | return TRUE; |
252b5132 RH |
4248 | } |
4249 | ||
c178919b NC |
4250 | /* Set the right machine number. */ |
4251 | ||
4252 | static bfd_boolean | |
57e8b36a | 4253 | elf32_arm_object_p (bfd *abfd) |
c178919b | 4254 | { |
5a6c6817 | 4255 | unsigned int mach; |
57e8b36a | 4256 | |
5a6c6817 | 4257 | mach = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION); |
c178919b | 4258 | |
5a6c6817 NC |
4259 | if (mach != bfd_mach_arm_unknown) |
4260 | bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach); | |
4261 | ||
4262 | else if (elf_elfheader (abfd)->e_flags & EF_ARM_MAVERICK_FLOAT) | |
4263 | bfd_default_set_arch_mach (abfd, bfd_arch_arm, bfd_mach_arm_ep9312); | |
e16bb312 | 4264 | |
e16bb312 | 4265 | else |
5a6c6817 | 4266 | bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach); |
c178919b NC |
4267 | |
4268 | return TRUE; | |
4269 | } | |
4270 | ||
fc830a83 | 4271 | /* Function to keep ARM specific flags in the ELF header. */ |
3c9458e9 | 4272 | |
b34976b6 | 4273 | static bfd_boolean |
57e8b36a | 4274 | elf32_arm_set_private_flags (bfd *abfd, flagword flags) |
252b5132 RH |
4275 | { |
4276 | if (elf_flags_init (abfd) | |
4277 | && elf_elfheader (abfd)->e_flags != flags) | |
4278 | { | |
fc830a83 NC |
4279 | if (EF_ARM_EABI_VERSION (flags) == EF_ARM_EABI_UNKNOWN) |
4280 | { | |
fd2ec330 | 4281 | if (flags & EF_ARM_INTERWORK) |
d003868e AM |
4282 | (*_bfd_error_handler) |
4283 | (_("Warning: Not setting interworking flag of %B since it has already been specified as non-interworking"), | |
4284 | abfd); | |
fc830a83 | 4285 | else |
d003868e AM |
4286 | _bfd_error_handler |
4287 | (_("Warning: Clearing the interworking flag of %B due to outside request"), | |
4288 | abfd); | |
fc830a83 | 4289 | } |
252b5132 RH |
4290 | } |
4291 | else | |
4292 | { | |
4293 | elf_elfheader (abfd)->e_flags = flags; | |
b34976b6 | 4294 | elf_flags_init (abfd) = TRUE; |
252b5132 RH |
4295 | } |
4296 | ||
b34976b6 | 4297 | return TRUE; |
252b5132 RH |
4298 | } |
4299 | ||
fc830a83 | 4300 | /* Copy backend specific data from one object module to another. */ |
9b485d32 | 4301 | |
b34976b6 | 4302 | static bfd_boolean |
57e8b36a | 4303 | elf32_arm_copy_private_bfd_data (bfd *ibfd, bfd *obfd) |
252b5132 RH |
4304 | { |
4305 | flagword in_flags; | |
4306 | flagword out_flags; | |
4307 | ||
fc830a83 | 4308 | if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour |
252b5132 | 4309 | || bfd_get_flavour (obfd) != bfd_target_elf_flavour) |
b34976b6 | 4310 | return TRUE; |
252b5132 | 4311 | |
fc830a83 | 4312 | in_flags = elf_elfheader (ibfd)->e_flags; |
252b5132 RH |
4313 | out_flags = elf_elfheader (obfd)->e_flags; |
4314 | ||
fc830a83 NC |
4315 | if (elf_flags_init (obfd) |
4316 | && EF_ARM_EABI_VERSION (out_flags) == EF_ARM_EABI_UNKNOWN | |
4317 | && in_flags != out_flags) | |
252b5132 | 4318 | { |
252b5132 | 4319 | /* Cannot mix APCS26 and APCS32 code. */ |
fd2ec330 | 4320 | if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26)) |
b34976b6 | 4321 | return FALSE; |
252b5132 RH |
4322 | |
4323 | /* Cannot mix float APCS and non-float APCS code. */ | |
fd2ec330 | 4324 | if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT)) |
b34976b6 | 4325 | return FALSE; |
252b5132 RH |
4326 | |
4327 | /* If the src and dest have different interworking flags | |
4328 | then turn off the interworking bit. */ | |
fd2ec330 | 4329 | if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK)) |
252b5132 | 4330 | { |
fd2ec330 | 4331 | if (out_flags & EF_ARM_INTERWORK) |
d003868e AM |
4332 | _bfd_error_handler |
4333 | (_("Warning: Clearing the interworking flag of %B because non-interworking code in %B has been linked with it"), | |
4334 | obfd, ibfd); | |
252b5132 | 4335 | |
fd2ec330 | 4336 | in_flags &= ~EF_ARM_INTERWORK; |
252b5132 | 4337 | } |
1006ba19 PB |
4338 | |
4339 | /* Likewise for PIC, though don't warn for this case. */ | |
fd2ec330 PB |
4340 | if ((in_flags & EF_ARM_PIC) != (out_flags & EF_ARM_PIC)) |
4341 | in_flags &= ~EF_ARM_PIC; | |
252b5132 RH |
4342 | } |
4343 | ||
4344 | elf_elfheader (obfd)->e_flags = in_flags; | |
b34976b6 | 4345 | elf_flags_init (obfd) = TRUE; |
252b5132 | 4346 | |
94a3258f PB |
4347 | /* Also copy the EI_OSABI field. */ |
4348 | elf_elfheader (obfd)->e_ident[EI_OSABI] = | |
4349 | elf_elfheader (ibfd)->e_ident[EI_OSABI]; | |
4350 | ||
b34976b6 | 4351 | return TRUE; |
252b5132 RH |
4352 | } |
4353 | ||
4354 | /* Merge backend specific data from an object file to the output | |
4355 | object file when linking. */ | |
9b485d32 | 4356 | |
b34976b6 | 4357 | static bfd_boolean |
57e8b36a | 4358 | elf32_arm_merge_private_bfd_data (bfd * ibfd, bfd * obfd) |
252b5132 RH |
4359 | { |
4360 | flagword out_flags; | |
4361 | flagword in_flags; | |
b34976b6 | 4362 | bfd_boolean flags_compatible = TRUE; |
cf919dfd | 4363 | asection *sec; |
252b5132 | 4364 | |
9b485d32 | 4365 | /* Check if we have the same endianess. */ |
82e51918 | 4366 | if (! _bfd_generic_verify_endian_match (ibfd, obfd)) |
b34976b6 | 4367 | return FALSE; |
1fe494a5 | 4368 | |
252b5132 RH |
4369 | if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour |
4370 | || bfd_get_flavour (obfd) != bfd_target_elf_flavour) | |
b34976b6 | 4371 | return TRUE; |
252b5132 | 4372 | |
252b5132 RH |
4373 | /* The input BFD must have had its flags initialised. */ |
4374 | /* The following seems bogus to me -- The flags are initialized in | |
4375 | the assembler but I don't think an elf_flags_init field is | |
9b485d32 | 4376 | written into the object. */ |
252b5132 RH |
4377 | /* BFD_ASSERT (elf_flags_init (ibfd)); */ |
4378 | ||
4379 | in_flags = elf_elfheader (ibfd)->e_flags; | |
4380 | out_flags = elf_elfheader (obfd)->e_flags; | |
4381 | ||
4382 | if (!elf_flags_init (obfd)) | |
4383 | { | |
fe077fa6 NC |
4384 | /* If the input is the default architecture and had the default |
4385 | flags then do not bother setting the flags for the output | |
4386 | architecture, instead allow future merges to do this. If no | |
4387 | future merges ever set these flags then they will retain their | |
4388 | uninitialised values, which surprise surprise, correspond | |
252b5132 | 4389 | to the default values. */ |
fe077fa6 NC |
4390 | if (bfd_get_arch_info (ibfd)->the_default |
4391 | && elf_elfheader (ibfd)->e_flags == 0) | |
b34976b6 | 4392 | return TRUE; |
252b5132 | 4393 | |
b34976b6 | 4394 | elf_flags_init (obfd) = TRUE; |
252b5132 RH |
4395 | elf_elfheader (obfd)->e_flags = in_flags; |
4396 | ||
4397 | if (bfd_get_arch (obfd) == bfd_get_arch (ibfd) | |
4398 | && bfd_get_arch_info (obfd)->the_default) | |
4399 | return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd)); | |
4400 | ||
b34976b6 | 4401 | return TRUE; |
252b5132 RH |
4402 | } |
4403 | ||
5a6c6817 NC |
4404 | /* Determine what should happen if the input ARM architecture |
4405 | does not match the output ARM architecture. */ | |
4406 | if (! bfd_arm_merge_machines (ibfd, obfd)) | |
4407 | return FALSE; | |
e16bb312 | 4408 | |
1006ba19 | 4409 | /* Identical flags must be compatible. */ |
252b5132 | 4410 | if (in_flags == out_flags) |
b34976b6 | 4411 | return TRUE; |
252b5132 | 4412 | |
35a0f415 DJ |
4413 | /* Check to see if the input BFD actually contains any sections. If |
4414 | not, its flags may not have been initialised either, but it | |
4415 | cannot actually cause any incompatibility. Do not short-circuit | |
4416 | dynamic objects; their section list may be emptied by | |
d1f161ea | 4417 | elf_link_add_object_symbols. |
35a0f415 | 4418 | |
d1f161ea NC |
4419 | Also check to see if there are no code sections in the input. |
4420 | In this case there is no need to check for code specific flags. | |
4421 | XXX - do we need to worry about floating-point format compatability | |
4422 | in data sections ? */ | |
35a0f415 | 4423 | if (!(ibfd->flags & DYNAMIC)) |
cf919dfd | 4424 | { |
35a0f415 | 4425 | bfd_boolean null_input_bfd = TRUE; |
d1f161ea | 4426 | bfd_boolean only_data_sections = TRUE; |
35a0f415 DJ |
4427 | |
4428 | for (sec = ibfd->sections; sec != NULL; sec = sec->next) | |
cf919dfd | 4429 | { |
35a0f415 DJ |
4430 | /* Ignore synthetic glue sections. */ |
4431 | if (strcmp (sec->name, ".glue_7") | |
4432 | && strcmp (sec->name, ".glue_7t")) | |
4433 | { | |
d1f161ea NC |
4434 | if ((bfd_get_section_flags (ibfd, sec) |
4435 | & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS)) | |
4436 | == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS)) | |
4437 | only_data_sections = FALSE; | |
4438 | ||
35a0f415 DJ |
4439 | null_input_bfd = FALSE; |
4440 | break; | |
4441 | } | |
cf919dfd | 4442 | } |
d1f161ea NC |
4443 | |
4444 | if (null_input_bfd || only_data_sections) | |
35a0f415 | 4445 | return TRUE; |
cf919dfd | 4446 | } |
cf919dfd | 4447 | |
252b5132 | 4448 | /* Complain about various flag mismatches. */ |
fc830a83 NC |
4449 | if (EF_ARM_EABI_VERSION (in_flags) != EF_ARM_EABI_VERSION (out_flags)) |
4450 | { | |
d003868e | 4451 | _bfd_error_handler |
3656d5e3 | 4452 | (_("ERROR: Source object %B has EABI version %d, but target %B has EABI version %d"), |
d003868e AM |
4453 | ibfd, obfd, |
4454 | (in_flags & EF_ARM_EABIMASK) >> 24, | |
4455 | (out_flags & EF_ARM_EABIMASK) >> 24); | |
b34976b6 | 4456 | return FALSE; |
fc830a83 | 4457 | } |
252b5132 | 4458 | |
1006ba19 PB |
4459 | /* Not sure what needs to be checked for EABI versions >= 1. */ |
4460 | if (EF_ARM_EABI_VERSION (in_flags) == EF_ARM_EABI_UNKNOWN) | |
4461 | { | |
fd2ec330 | 4462 | if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26)) |
1006ba19 | 4463 | { |
d003868e AM |
4464 | _bfd_error_handler |
4465 | (_("ERROR: %B is compiled for APCS-%d, whereas target %B uses APCS-%d"), | |
4466 | ibfd, obfd, | |
4467 | in_flags & EF_ARM_APCS_26 ? 26 : 32, | |
4468 | out_flags & EF_ARM_APCS_26 ? 26 : 32); | |
b34976b6 | 4469 | flags_compatible = FALSE; |
1006ba19 | 4470 | } |
252b5132 | 4471 | |
fd2ec330 | 4472 | if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT)) |
1006ba19 | 4473 | { |
5eefb65f | 4474 | if (in_flags & EF_ARM_APCS_FLOAT) |
d003868e AM |
4475 | _bfd_error_handler |
4476 | (_("ERROR: %B passes floats in float registers, whereas %B passes them in integer registers"), | |
4477 | ibfd, obfd); | |
5eefb65f | 4478 | else |
d003868e AM |
4479 | _bfd_error_handler |
4480 | (_("ERROR: %B passes floats in integer registers, whereas %B passes them in float registers"), | |
4481 | ibfd, obfd); | |
63b0f745 | 4482 | |
b34976b6 | 4483 | flags_compatible = FALSE; |
1006ba19 | 4484 | } |
252b5132 | 4485 | |
96a846ea | 4486 | if ((in_flags & EF_ARM_VFP_FLOAT) != (out_flags & EF_ARM_VFP_FLOAT)) |
1006ba19 | 4487 | { |
96a846ea | 4488 | if (in_flags & EF_ARM_VFP_FLOAT) |
d003868e AM |
4489 | _bfd_error_handler |
4490 | (_("ERROR: %B uses VFP instructions, whereas %B does not"), | |
4491 | ibfd, obfd); | |
5eefb65f | 4492 | else |
d003868e AM |
4493 | _bfd_error_handler |
4494 | (_("ERROR: %B uses FPA instructions, whereas %B does not"), | |
4495 | ibfd, obfd); | |
fde78edd NC |
4496 | |
4497 | flags_compatible = FALSE; | |
4498 | } | |
4499 | ||
4500 | if ((in_flags & EF_ARM_MAVERICK_FLOAT) != (out_flags & EF_ARM_MAVERICK_FLOAT)) | |
4501 | { | |
4502 | if (in_flags & EF_ARM_MAVERICK_FLOAT) | |
d003868e AM |
4503 | _bfd_error_handler |
4504 | (_("ERROR: %B uses Maverick instructions, whereas %B does not"), | |
4505 | ibfd, obfd); | |
fde78edd | 4506 | else |
d003868e AM |
4507 | _bfd_error_handler |
4508 | (_("ERROR: %B does not use Maverick instructions, whereas %B does"), | |
4509 | ibfd, obfd); | |
63b0f745 | 4510 | |
b34976b6 | 4511 | flags_compatible = FALSE; |
1006ba19 | 4512 | } |
96a846ea RE |
4513 | |
4514 | #ifdef EF_ARM_SOFT_FLOAT | |
4515 | if ((in_flags & EF_ARM_SOFT_FLOAT) != (out_flags & EF_ARM_SOFT_FLOAT)) | |
4516 | { | |
4517 | /* We can allow interworking between code that is VFP format | |
4518 | layout, and uses either soft float or integer regs for | |
4519 | passing floating point arguments and results. We already | |
4520 | know that the APCS_FLOAT flags match; similarly for VFP | |
4521 | flags. */ | |
4522 | if ((in_flags & EF_ARM_APCS_FLOAT) != 0 | |
4523 | || (in_flags & EF_ARM_VFP_FLOAT) == 0) | |
4524 | { | |
4525 | if (in_flags & EF_ARM_SOFT_FLOAT) | |
d003868e AM |
4526 | _bfd_error_handler |
4527 | (_("ERROR: %B uses software FP, whereas %B uses hardware FP"), | |
4528 | ibfd, obfd); | |
96a846ea | 4529 | else |
d003868e AM |
4530 | _bfd_error_handler |
4531 | (_("ERROR: %B uses hardware FP, whereas %B uses software FP"), | |
4532 | ibfd, obfd); | |
96a846ea | 4533 | |
b34976b6 | 4534 | flags_compatible = FALSE; |
96a846ea RE |
4535 | } |
4536 | } | |
ee43f35e | 4537 | #endif |
252b5132 | 4538 | |
1006ba19 | 4539 | /* Interworking mismatch is only a warning. */ |
fd2ec330 | 4540 | if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK)) |
8f615d07 | 4541 | { |
e3c8793a NC |
4542 | if (in_flags & EF_ARM_INTERWORK) |
4543 | { | |
d003868e AM |
4544 | _bfd_error_handler |
4545 | (_("Warning: %B supports interworking, whereas %B does not"), | |
4546 | ibfd, obfd); | |
e3c8793a NC |
4547 | } |
4548 | else | |
4549 | { | |
d003868e AM |
4550 | _bfd_error_handler |
4551 | (_("Warning: %B does not support interworking, whereas %B does"), | |
4552 | ibfd, obfd); | |
e3c8793a | 4553 | } |
8f615d07 | 4554 | } |
252b5132 | 4555 | } |
63b0f745 | 4556 | |
1006ba19 | 4557 | return flags_compatible; |
252b5132 RH |
4558 | } |
4559 | ||
9b485d32 NC |
4560 | /* Display the flags field. */ |
4561 | ||
b34976b6 | 4562 | static bfd_boolean |
57e8b36a | 4563 | elf32_arm_print_private_bfd_data (bfd *abfd, void * ptr) |
252b5132 | 4564 | { |
fc830a83 NC |
4565 | FILE * file = (FILE *) ptr; |
4566 | unsigned long flags; | |
252b5132 RH |
4567 | |
4568 | BFD_ASSERT (abfd != NULL && ptr != NULL); | |
4569 | ||
4570 | /* Print normal ELF private data. */ | |
4571 | _bfd_elf_print_private_bfd_data (abfd, ptr); | |
4572 | ||
fc830a83 | 4573 | flags = elf_elfheader (abfd)->e_flags; |
9b485d32 NC |
4574 | /* Ignore init flag - it may not be set, despite the flags field |
4575 | containing valid data. */ | |
252b5132 RH |
4576 | |
4577 | /* xgettext:c-format */ | |
9b485d32 | 4578 | fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags); |
252b5132 | 4579 | |
fc830a83 NC |
4580 | switch (EF_ARM_EABI_VERSION (flags)) |
4581 | { | |
4582 | case EF_ARM_EABI_UNKNOWN: | |
4cc11e76 | 4583 | /* The following flag bits are GNU extensions and not part of the |
fc830a83 NC |
4584 | official ARM ELF extended ABI. Hence they are only decoded if |
4585 | the EABI version is not set. */ | |
fd2ec330 | 4586 | if (flags & EF_ARM_INTERWORK) |
9b485d32 | 4587 | fprintf (file, _(" [interworking enabled]")); |
9a5aca8c | 4588 | |
fd2ec330 | 4589 | if (flags & EF_ARM_APCS_26) |
6c571f00 | 4590 | fprintf (file, " [APCS-26]"); |
fc830a83 | 4591 | else |
6c571f00 | 4592 | fprintf (file, " [APCS-32]"); |
9a5aca8c | 4593 | |
96a846ea RE |
4594 | if (flags & EF_ARM_VFP_FLOAT) |
4595 | fprintf (file, _(" [VFP float format]")); | |
fde78edd NC |
4596 | else if (flags & EF_ARM_MAVERICK_FLOAT) |
4597 | fprintf (file, _(" [Maverick float format]")); | |
96a846ea RE |
4598 | else |
4599 | fprintf (file, _(" [FPA float format]")); | |
4600 | ||
fd2ec330 | 4601 | if (flags & EF_ARM_APCS_FLOAT) |
9b485d32 | 4602 | fprintf (file, _(" [floats passed in float registers]")); |
9a5aca8c | 4603 | |
fd2ec330 | 4604 | if (flags & EF_ARM_PIC) |
9b485d32 | 4605 | fprintf (file, _(" [position independent]")); |
fc830a83 | 4606 | |
fd2ec330 | 4607 | if (flags & EF_ARM_NEW_ABI) |
9b485d32 | 4608 | fprintf (file, _(" [new ABI]")); |
9a5aca8c | 4609 | |
fd2ec330 | 4610 | if (flags & EF_ARM_OLD_ABI) |
9b485d32 | 4611 | fprintf (file, _(" [old ABI]")); |
9a5aca8c | 4612 | |
fd2ec330 | 4613 | if (flags & EF_ARM_SOFT_FLOAT) |
9b485d32 | 4614 | fprintf (file, _(" [software FP]")); |
9a5aca8c | 4615 | |
96a846ea RE |
4616 | flags &= ~(EF_ARM_INTERWORK | EF_ARM_APCS_26 | EF_ARM_APCS_FLOAT |
4617 | | EF_ARM_PIC | EF_ARM_NEW_ABI | EF_ARM_OLD_ABI | |
fde78edd NC |
4618 | | EF_ARM_SOFT_FLOAT | EF_ARM_VFP_FLOAT |
4619 | | EF_ARM_MAVERICK_FLOAT); | |
fc830a83 | 4620 | break; |
9a5aca8c | 4621 | |
fc830a83 | 4622 | case EF_ARM_EABI_VER1: |
9b485d32 | 4623 | fprintf (file, _(" [Version1 EABI]")); |
9a5aca8c | 4624 | |
fc830a83 | 4625 | if (flags & EF_ARM_SYMSARESORTED) |
9b485d32 | 4626 | fprintf (file, _(" [sorted symbol table]")); |
fc830a83 | 4627 | else |
9b485d32 | 4628 | fprintf (file, _(" [unsorted symbol table]")); |
9a5aca8c | 4629 | |
fc830a83 NC |
4630 | flags &= ~ EF_ARM_SYMSARESORTED; |
4631 | break; | |
9a5aca8c | 4632 | |
fd2ec330 PB |
4633 | case EF_ARM_EABI_VER2: |
4634 | fprintf (file, _(" [Version2 EABI]")); | |
4635 | ||
4636 | if (flags & EF_ARM_SYMSARESORTED) | |
4637 | fprintf (file, _(" [sorted symbol table]")); | |
4638 | else | |
4639 | fprintf (file, _(" [unsorted symbol table]")); | |
4640 | ||
4641 | if (flags & EF_ARM_DYNSYMSUSESEGIDX) | |
4642 | fprintf (file, _(" [dynamic symbols use segment index]")); | |
4643 | ||
4644 | if (flags & EF_ARM_MAPSYMSFIRST) | |
4645 | fprintf (file, _(" [mapping symbols precede others]")); | |
4646 | ||
99e4ae17 | 4647 | flags &= ~(EF_ARM_SYMSARESORTED | EF_ARM_DYNSYMSUSESEGIDX |
fd2ec330 PB |
4648 | | EF_ARM_MAPSYMSFIRST); |
4649 | break; | |
4650 | ||
d507cf36 PB |
4651 | case EF_ARM_EABI_VER3: |
4652 | fprintf (file, _(" [Version3 EABI]")); | |
8cb51566 PB |
4653 | break; |
4654 | ||
4655 | case EF_ARM_EABI_VER4: | |
4656 | fprintf (file, _(" [Version4 EABI]")); | |
d507cf36 PB |
4657 | |
4658 | if (flags & EF_ARM_BE8) | |
4659 | fprintf (file, _(" [BE8]")); | |
4660 | ||
4661 | if (flags & EF_ARM_LE8) | |
4662 | fprintf (file, _(" [LE8]")); | |
4663 | ||
4664 | flags &= ~(EF_ARM_LE8 | EF_ARM_BE8); | |
4665 | break; | |
4666 | ||
fc830a83 | 4667 | default: |
9b485d32 | 4668 | fprintf (file, _(" <EABI version unrecognised>")); |
fc830a83 NC |
4669 | break; |
4670 | } | |
252b5132 | 4671 | |
fc830a83 | 4672 | flags &= ~ EF_ARM_EABIMASK; |
252b5132 | 4673 | |
fc830a83 | 4674 | if (flags & EF_ARM_RELEXEC) |
9b485d32 | 4675 | fprintf (file, _(" [relocatable executable]")); |
252b5132 | 4676 | |
fc830a83 | 4677 | if (flags & EF_ARM_HASENTRY) |
9b485d32 | 4678 | fprintf (file, _(" [has entry point]")); |
252b5132 | 4679 | |
fc830a83 NC |
4680 | flags &= ~ (EF_ARM_RELEXEC | EF_ARM_HASENTRY); |
4681 | ||
4682 | if (flags) | |
9b485d32 | 4683 | fprintf (file, _("<Unrecognised flag bits set>")); |
9a5aca8c | 4684 | |
252b5132 RH |
4685 | fputc ('\n', file); |
4686 | ||
b34976b6 | 4687 | return TRUE; |
252b5132 RH |
4688 | } |
4689 | ||
4690 | static int | |
57e8b36a | 4691 | elf32_arm_get_symbol_type (Elf_Internal_Sym * elf_sym, int type) |
252b5132 | 4692 | { |
2f0ca46a NC |
4693 | switch (ELF_ST_TYPE (elf_sym->st_info)) |
4694 | { | |
4695 | case STT_ARM_TFUNC: | |
4696 | return ELF_ST_TYPE (elf_sym->st_info); | |
ce855c42 | 4697 | |
2f0ca46a NC |
4698 | case STT_ARM_16BIT: |
4699 | /* If the symbol is not an object, return the STT_ARM_16BIT flag. | |
4700 | This allows us to distinguish between data used by Thumb instructions | |
4701 | and non-data (which is probably code) inside Thumb regions of an | |
4702 | executable. */ | |
4703 | if (type != STT_OBJECT) | |
4704 | return ELF_ST_TYPE (elf_sym->st_info); | |
4705 | break; | |
9a5aca8c | 4706 | |
ce855c42 NC |
4707 | default: |
4708 | break; | |
2f0ca46a NC |
4709 | } |
4710 | ||
4711 | return type; | |
252b5132 | 4712 | } |
f21f3fe0 | 4713 | |
252b5132 | 4714 | static asection * |
57e8b36a NC |
4715 | elf32_arm_gc_mark_hook (asection * sec, |
4716 | struct bfd_link_info * info ATTRIBUTE_UNUSED, | |
4717 | Elf_Internal_Rela * rel, | |
4718 | struct elf_link_hash_entry * h, | |
4719 | Elf_Internal_Sym * sym) | |
252b5132 RH |
4720 | { |
4721 | if (h != NULL) | |
4722 | { | |
4723 | switch (ELF32_R_TYPE (rel->r_info)) | |
4724 | { | |
4725 | case R_ARM_GNU_VTINHERIT: | |
4726 | case R_ARM_GNU_VTENTRY: | |
4727 | break; | |
4728 | ||
4729 | default: | |
4730 | switch (h->root.type) | |
4731 | { | |
4732 | case bfd_link_hash_defined: | |
4733 | case bfd_link_hash_defweak: | |
4734 | return h->root.u.def.section; | |
4735 | ||
4736 | case bfd_link_hash_common: | |
4737 | return h->root.u.c.p->section; | |
e049a0de ILT |
4738 | |
4739 | default: | |
4740 | break; | |
252b5132 RH |
4741 | } |
4742 | } | |
4743 | } | |
4744 | else | |
1e2f5b6e | 4745 | return bfd_section_from_elf_index (sec->owner, sym->st_shndx); |
9ad5cbcf | 4746 | |
252b5132 RH |
4747 | return NULL; |
4748 | } | |
4749 | ||
780a67af NC |
4750 | /* Update the got entry reference counts for the section being removed. */ |
4751 | ||
b34976b6 | 4752 | static bfd_boolean |
ba93b8ac DJ |
4753 | elf32_arm_gc_sweep_hook (bfd * abfd, |
4754 | struct bfd_link_info * info, | |
4755 | asection * sec, | |
4756 | const Elf_Internal_Rela * relocs) | |
252b5132 | 4757 | { |
5e681ec4 PB |
4758 | Elf_Internal_Shdr *symtab_hdr; |
4759 | struct elf_link_hash_entry **sym_hashes; | |
4760 | bfd_signed_vma *local_got_refcounts; | |
4761 | const Elf_Internal_Rela *rel, *relend; | |
eb043451 PB |
4762 | struct elf32_arm_link_hash_table * globals; |
4763 | ||
4764 | globals = elf32_arm_hash_table (info); | |
5e681ec4 PB |
4765 | |
4766 | elf_section_data (sec)->local_dynrel = NULL; | |
4767 | ||
4768 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; | |
4769 | sym_hashes = elf_sym_hashes (abfd); | |
4770 | local_got_refcounts = elf_local_got_refcounts (abfd); | |
4771 | ||
4772 | relend = relocs + sec->reloc_count; | |
4773 | for (rel = relocs; rel < relend; rel++) | |
eb043451 | 4774 | { |
3eb128b2 AM |
4775 | unsigned long r_symndx; |
4776 | struct elf_link_hash_entry *h = NULL; | |
eb043451 | 4777 | int r_type; |
5e681ec4 | 4778 | |
3eb128b2 AM |
4779 | r_symndx = ELF32_R_SYM (rel->r_info); |
4780 | if (r_symndx >= symtab_hdr->sh_info) | |
4781 | { | |
4782 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
4783 | while (h->root.type == bfd_link_hash_indirect | |
4784 | || h->root.type == bfd_link_hash_warning) | |
4785 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
4786 | } | |
4787 | ||
eb043451 | 4788 | r_type = ELF32_R_TYPE (rel->r_info); |
eb043451 | 4789 | r_type = arm_real_reloc_type (globals, r_type); |
eb043451 PB |
4790 | switch (r_type) |
4791 | { | |
4792 | case R_ARM_GOT32: | |
eb043451 | 4793 | case R_ARM_GOT_PREL: |
ba93b8ac DJ |
4794 | case R_ARM_TLS_GD32: |
4795 | case R_ARM_TLS_IE32: | |
3eb128b2 | 4796 | if (h != NULL) |
eb043451 | 4797 | { |
eb043451 PB |
4798 | if (h->got.refcount > 0) |
4799 | h->got.refcount -= 1; | |
4800 | } | |
4801 | else if (local_got_refcounts != NULL) | |
4802 | { | |
4803 | if (local_got_refcounts[r_symndx] > 0) | |
4804 | local_got_refcounts[r_symndx] -= 1; | |
4805 | } | |
4806 | break; | |
4807 | ||
ba93b8ac DJ |
4808 | case R_ARM_TLS_LDM32: |
4809 | elf32_arm_hash_table (info)->tls_ldm_got.refcount -= 1; | |
4810 | break; | |
4811 | ||
eb043451 PB |
4812 | case R_ARM_ABS32: |
4813 | case R_ARM_REL32: | |
4814 | case R_ARM_PC24: | |
4815 | case R_ARM_PLT32: | |
5b5bb741 PB |
4816 | case R_ARM_CALL: |
4817 | case R_ARM_JUMP24: | |
eb043451 | 4818 | case R_ARM_PREL31: |
c19d1205 | 4819 | case R_ARM_THM_CALL: |
b7693d02 DJ |
4820 | /* Should the interworking branches be here also? */ |
4821 | ||
3eb128b2 | 4822 | if (h != NULL) |
eb043451 PB |
4823 | { |
4824 | struct elf32_arm_link_hash_entry *eh; | |
4825 | struct elf32_arm_relocs_copied **pp; | |
4826 | struct elf32_arm_relocs_copied *p; | |
5e681ec4 | 4827 | |
b7693d02 | 4828 | eh = (struct elf32_arm_link_hash_entry *) h; |
5e681ec4 | 4829 | |
eb043451 | 4830 | if (h->plt.refcount > 0) |
b7693d02 DJ |
4831 | { |
4832 | h->plt.refcount -= 1; | |
c19d1205 | 4833 | if (ELF32_R_TYPE (rel->r_info) == R_ARM_THM_CALL) |
b7693d02 DJ |
4834 | eh->plt_thumb_refcount--; |
4835 | } | |
5e681ec4 | 4836 | |
eb043451 | 4837 | if (r_type == R_ARM_ABS32 |
eb043451 PB |
4838 | || r_type == R_ARM_REL32) |
4839 | { | |
eb043451 PB |
4840 | for (pp = &eh->relocs_copied; (p = *pp) != NULL; |
4841 | pp = &p->next) | |
4842 | if (p->section == sec) | |
4843 | { | |
4844 | p->count -= 1; | |
ba93b8ac DJ |
4845 | if (ELF32_R_TYPE (rel->r_info) == R_ARM_REL32) |
4846 | p->pc_count -= 1; | |
eb043451 PB |
4847 | if (p->count == 0) |
4848 | *pp = p->next; | |
4849 | break; | |
4850 | } | |
4851 | } | |
4852 | } | |
4853 | break; | |
5e681ec4 | 4854 | |
eb043451 PB |
4855 | default: |
4856 | break; | |
4857 | } | |
4858 | } | |
5e681ec4 | 4859 | |
b34976b6 | 4860 | return TRUE; |
252b5132 RH |
4861 | } |
4862 | ||
780a67af NC |
4863 | /* Look through the relocs for a section during the first phase. */ |
4864 | ||
b34976b6 | 4865 | static bfd_boolean |
57e8b36a NC |
4866 | elf32_arm_check_relocs (bfd *abfd, struct bfd_link_info *info, |
4867 | asection *sec, const Elf_Internal_Rela *relocs) | |
252b5132 | 4868 | { |
b34976b6 AM |
4869 | Elf_Internal_Shdr *symtab_hdr; |
4870 | struct elf_link_hash_entry **sym_hashes; | |
4871 | struct elf_link_hash_entry **sym_hashes_end; | |
4872 | const Elf_Internal_Rela *rel; | |
4873 | const Elf_Internal_Rela *rel_end; | |
4874 | bfd *dynobj; | |
5e681ec4 | 4875 | asection *sreloc; |
b34976b6 | 4876 | bfd_vma *local_got_offsets; |
5e681ec4 | 4877 | struct elf32_arm_link_hash_table *htab; |
9a5aca8c | 4878 | |
1049f94e | 4879 | if (info->relocatable) |
b34976b6 | 4880 | return TRUE; |
9a5aca8c | 4881 | |
5e681ec4 PB |
4882 | htab = elf32_arm_hash_table (info); |
4883 | sreloc = NULL; | |
9a5aca8c | 4884 | |
67687978 PB |
4885 | /* Create dynamic sections for relocatable executables so that we can |
4886 | copy relocations. */ | |
4887 | if (htab->root.is_relocatable_executable | |
4888 | && ! htab->root.dynamic_sections_created) | |
4889 | { | |
4890 | if (! _bfd_elf_link_create_dynamic_sections (abfd, info)) | |
4891 | return FALSE; | |
4892 | } | |
4893 | ||
252b5132 RH |
4894 | dynobj = elf_hash_table (info)->dynobj; |
4895 | local_got_offsets = elf_local_got_offsets (abfd); | |
f21f3fe0 | 4896 | |
252b5132 RH |
4897 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
4898 | sym_hashes = elf_sym_hashes (abfd); | |
9b485d32 NC |
4899 | sym_hashes_end = sym_hashes |
4900 | + symtab_hdr->sh_size / sizeof (Elf32_External_Sym); | |
4901 | ||
252b5132 RH |
4902 | if (!elf_bad_symtab (abfd)) |
4903 | sym_hashes_end -= symtab_hdr->sh_info; | |
9b485d32 | 4904 | |
252b5132 RH |
4905 | rel_end = relocs + sec->reloc_count; |
4906 | for (rel = relocs; rel < rel_end; rel++) | |
4907 | { | |
4908 | struct elf_link_hash_entry *h; | |
b7693d02 | 4909 | struct elf32_arm_link_hash_entry *eh; |
252b5132 | 4910 | unsigned long r_symndx; |
eb043451 | 4911 | int r_type; |
9a5aca8c | 4912 | |
252b5132 | 4913 | r_symndx = ELF32_R_SYM (rel->r_info); |
eb043451 | 4914 | r_type = ELF32_R_TYPE (rel->r_info); |
eb043451 | 4915 | r_type = arm_real_reloc_type (htab, r_type); |
ba93b8ac DJ |
4916 | |
4917 | if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr)) | |
4918 | { | |
4919 | (*_bfd_error_handler) (_("%B: bad symbol index: %d"), abfd, | |
4920 | r_symndx); | |
4921 | return FALSE; | |
4922 | } | |
4923 | ||
252b5132 RH |
4924 | if (r_symndx < symtab_hdr->sh_info) |
4925 | h = NULL; | |
4926 | else | |
4927 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
9a5aca8c | 4928 | |
b7693d02 DJ |
4929 | eh = (struct elf32_arm_link_hash_entry *) h; |
4930 | ||
eb043451 | 4931 | switch (r_type) |
252b5132 | 4932 | { |
5e681ec4 | 4933 | case R_ARM_GOT32: |
eb043451 | 4934 | case R_ARM_GOT_PREL: |
ba93b8ac DJ |
4935 | case R_ARM_TLS_GD32: |
4936 | case R_ARM_TLS_IE32: | |
5e681ec4 | 4937 | /* This symbol requires a global offset table entry. */ |
ba93b8ac DJ |
4938 | { |
4939 | int tls_type, old_tls_type; | |
5e681ec4 | 4940 | |
ba93b8ac DJ |
4941 | switch (r_type) |
4942 | { | |
4943 | case R_ARM_TLS_GD32: tls_type = GOT_TLS_GD; break; | |
4944 | case R_ARM_TLS_IE32: tls_type = GOT_TLS_IE; break; | |
4945 | default: tls_type = GOT_NORMAL; break; | |
4946 | } | |
252b5132 | 4947 | |
ba93b8ac DJ |
4948 | if (h != NULL) |
4949 | { | |
4950 | h->got.refcount++; | |
4951 | old_tls_type = elf32_arm_hash_entry (h)->tls_type; | |
4952 | } | |
4953 | else | |
4954 | { | |
4955 | bfd_signed_vma *local_got_refcounts; | |
4956 | ||
4957 | /* This is a global offset table entry for a local symbol. */ | |
4958 | local_got_refcounts = elf_local_got_refcounts (abfd); | |
4959 | if (local_got_refcounts == NULL) | |
4960 | { | |
4961 | bfd_size_type size; | |
4962 | ||
4963 | size = symtab_hdr->sh_info; | |
4964 | size *= (sizeof (bfd_signed_vma) + sizeof(char)); | |
4965 | local_got_refcounts = bfd_zalloc (abfd, size); | |
4966 | if (local_got_refcounts == NULL) | |
4967 | return FALSE; | |
4968 | elf_local_got_refcounts (abfd) = local_got_refcounts; | |
4969 | elf32_arm_local_got_tls_type (abfd) | |
4970 | = (char *) (local_got_refcounts + symtab_hdr->sh_info); | |
4971 | } | |
4972 | local_got_refcounts[r_symndx] += 1; | |
4973 | old_tls_type = elf32_arm_local_got_tls_type (abfd) [r_symndx]; | |
4974 | } | |
4975 | ||
4976 | /* We will already have issued an error message if there is a | |
4977 | TLS / non-TLS mismatch, based on the symbol type. We don't | |
4978 | support any linker relaxations. So just combine any TLS | |
4979 | types needed. */ | |
4980 | if (old_tls_type != GOT_UNKNOWN && old_tls_type != GOT_NORMAL | |
4981 | && tls_type != GOT_NORMAL) | |
4982 | tls_type |= old_tls_type; | |
4983 | ||
4984 | if (old_tls_type != tls_type) | |
4985 | { | |
4986 | if (h != NULL) | |
4987 | elf32_arm_hash_entry (h)->tls_type = tls_type; | |
4988 | else | |
4989 | elf32_arm_local_got_tls_type (abfd) [r_symndx] = tls_type; | |
4990 | } | |
4991 | } | |
4992 | /* Fall through */ | |
4993 | ||
4994 | case R_ARM_TLS_LDM32: | |
4995 | if (r_type == R_ARM_TLS_LDM32) | |
4996 | htab->tls_ldm_got.refcount++; | |
4997 | /* Fall through */ | |
252b5132 | 4998 | |
c19d1205 | 4999 | case R_ARM_GOTOFF32: |
5e681ec4 PB |
5000 | case R_ARM_GOTPC: |
5001 | if (htab->sgot == NULL) | |
5002 | { | |
5003 | if (htab->root.dynobj == NULL) | |
5004 | htab->root.dynobj = abfd; | |
5005 | if (!create_got_section (htab->root.dynobj, info)) | |
5006 | return FALSE; | |
5007 | } | |
252b5132 RH |
5008 | break; |
5009 | ||
5010 | case R_ARM_ABS32: | |
5011 | case R_ARM_REL32: | |
5012 | case R_ARM_PC24: | |
7359ea65 | 5013 | case R_ARM_PLT32: |
5b5bb741 PB |
5014 | case R_ARM_CALL: |
5015 | case R_ARM_JUMP24: | |
eb043451 | 5016 | case R_ARM_PREL31: |
c19d1205 | 5017 | case R_ARM_THM_CALL: |
b7693d02 | 5018 | /* Should the interworking branches be listed here? */ |
7359ea65 | 5019 | if (h != NULL) |
5e681ec4 PB |
5020 | { |
5021 | /* If this reloc is in a read-only section, we might | |
5022 | need a copy reloc. We can't check reliably at this | |
5023 | stage whether the section is read-only, as input | |
5024 | sections have not yet been mapped to output sections. | |
5025 | Tentatively set the flag for now, and correct in | |
5026 | adjust_dynamic_symbol. */ | |
7359ea65 | 5027 | if (!info->shared) |
f5385ebf | 5028 | h->non_got_ref = 1; |
7359ea65 | 5029 | |
5e681ec4 | 5030 | /* We may need a .plt entry if the function this reloc |
c84cd8ee DJ |
5031 | refers to is in a different object. We can't tell for |
5032 | sure yet, because something later might force the | |
5033 | symbol local. */ | |
eb043451 | 5034 | if (r_type == R_ARM_PC24 |
5b5bb741 PB |
5035 | || r_type == R_ARM_CALL |
5036 | || r_type == R_ARM_JUMP24 | |
ee06dc07 | 5037 | || r_type == R_ARM_PREL31 |
b7693d02 | 5038 | || r_type == R_ARM_PLT32 |
c19d1205 | 5039 | || r_type == R_ARM_THM_CALL) |
f5385ebf | 5040 | h->needs_plt = 1; |
4f199be3 DJ |
5041 | |
5042 | /* If we create a PLT entry, this relocation will reference | |
5043 | it, even if it's an ABS32 relocation. */ | |
5044 | h->plt.refcount += 1; | |
b7693d02 | 5045 | |
c19d1205 | 5046 | if (r_type == R_ARM_THM_CALL) |
b7693d02 | 5047 | eh->plt_thumb_refcount += 1; |
5e681ec4 PB |
5048 | } |
5049 | ||
67687978 PB |
5050 | /* If we are creating a shared library or relocatable executable, |
5051 | and this is a reloc against a global symbol, or a non PC | |
5052 | relative reloc against a local symbol, then we need to copy | |
5053 | the reloc into the shared library. However, if we are linking | |
5054 | with -Bsymbolic, we do not need to copy a reloc against a | |
252b5132 RH |
5055 | global symbol which is defined in an object we are |
5056 | including in the link (i.e., DEF_REGULAR is set). At | |
5057 | this point we have not seen all the input files, so it is | |
5058 | possible that DEF_REGULAR is not set now but will be set | |
5059 | later (it is never cleared). We account for that | |
5060 | possibility below by storing information in the | |
5e681ec4 | 5061 | relocs_copied field of the hash table entry. */ |
67687978 | 5062 | if ((info->shared || htab->root.is_relocatable_executable) |
5e681ec4 | 5063 | && (sec->flags & SEC_ALLOC) != 0 |
71a976dd DJ |
5064 | && (r_type == R_ARM_ABS32 |
5065 | || (h != NULL && ! h->needs_plt | |
5066 | && (! info->symbolic || ! h->def_regular)))) | |
252b5132 | 5067 | { |
5e681ec4 PB |
5068 | struct elf32_arm_relocs_copied *p, **head; |
5069 | ||
252b5132 RH |
5070 | /* When creating a shared object, we must copy these |
5071 | reloc types into the output file. We create a reloc | |
5072 | section in dynobj and make room for this reloc. */ | |
5073 | if (sreloc == NULL) | |
5074 | { | |
5075 | const char * name; | |
5076 | ||
5077 | name = (bfd_elf_string_from_elf_section | |
5078 | (abfd, | |
5079 | elf_elfheader (abfd)->e_shstrndx, | |
5080 | elf_section_data (sec)->rel_hdr.sh_name)); | |
5081 | if (name == NULL) | |
b34976b6 | 5082 | return FALSE; |
252b5132 RH |
5083 | |
5084 | BFD_ASSERT (strncmp (name, ".rel", 4) == 0 | |
99e4ae17 | 5085 | && strcmp (bfd_get_section_name (abfd, sec), |
252b5132 RH |
5086 | name + 4) == 0); |
5087 | ||
5088 | sreloc = bfd_get_section_by_name (dynobj, name); | |
5089 | if (sreloc == NULL) | |
5090 | { | |
5091 | flagword flags; | |
5092 | ||
252b5132 RH |
5093 | flags = (SEC_HAS_CONTENTS | SEC_READONLY |
5094 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
e5a52504 MM |
5095 | if ((sec->flags & SEC_ALLOC) != 0 |
5096 | /* BPABI objects never have dynamic | |
5097 | relocations mapped. */ | |
5098 | && !htab->symbian_p) | |
252b5132 | 5099 | flags |= SEC_ALLOC | SEC_LOAD; |
3496cb2a L |
5100 | sreloc = bfd_make_section_with_flags (dynobj, |
5101 | name, | |
5102 | flags); | |
252b5132 | 5103 | if (sreloc == NULL |
252b5132 | 5104 | || ! bfd_set_section_alignment (dynobj, sreloc, 2)) |
b34976b6 | 5105 | return FALSE; |
252b5132 | 5106 | } |
5e681ec4 PB |
5107 | |
5108 | elf_section_data (sec)->sreloc = sreloc; | |
252b5132 RH |
5109 | } |
5110 | ||
5e681ec4 PB |
5111 | /* If this is a global symbol, we count the number of |
5112 | relocations we need for this symbol. */ | |
5113 | if (h != NULL) | |
252b5132 | 5114 | { |
5e681ec4 PB |
5115 | head = &((struct elf32_arm_link_hash_entry *) h)->relocs_copied; |
5116 | } | |
5117 | else | |
5118 | { | |
5119 | /* Track dynamic relocs needed for local syms too. | |
5120 | We really need local syms available to do this | |
5121 | easily. Oh well. */ | |
57e8b36a | 5122 | |
5e681ec4 PB |
5123 | asection *s; |
5124 | s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, | |
5125 | sec, r_symndx); | |
5126 | if (s == NULL) | |
5127 | return FALSE; | |
57e8b36a | 5128 | |
5e681ec4 PB |
5129 | head = ((struct elf32_arm_relocs_copied **) |
5130 | &elf_section_data (s)->local_dynrel); | |
5131 | } | |
57e8b36a | 5132 | |
5e681ec4 PB |
5133 | p = *head; |
5134 | if (p == NULL || p->section != sec) | |
5135 | { | |
5136 | bfd_size_type amt = sizeof *p; | |
57e8b36a | 5137 | |
5e681ec4 | 5138 | p = bfd_alloc (htab->root.dynobj, amt); |
252b5132 | 5139 | if (p == NULL) |
5e681ec4 PB |
5140 | return FALSE; |
5141 | p->next = *head; | |
5142 | *head = p; | |
5143 | p->section = sec; | |
5144 | p->count = 0; | |
ba93b8ac | 5145 | p->pc_count = 0; |
252b5132 | 5146 | } |
57e8b36a | 5147 | |
ba93b8ac DJ |
5148 | if (r_type == R_ARM_REL32) |
5149 | p->pc_count += 1; | |
71a976dd | 5150 | p->count += 1; |
252b5132 RH |
5151 | } |
5152 | break; | |
5153 | ||
5154 | /* This relocation describes the C++ object vtable hierarchy. | |
5155 | Reconstruct it for later use during GC. */ | |
5156 | case R_ARM_GNU_VTINHERIT: | |
c152c796 | 5157 | if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) |
b34976b6 | 5158 | return FALSE; |
252b5132 | 5159 | break; |
9a5aca8c | 5160 | |
252b5132 RH |
5161 | /* This relocation describes which C++ vtable entries are actually |
5162 | used. Record for later use during GC. */ | |
5163 | case R_ARM_GNU_VTENTRY: | |
c152c796 | 5164 | if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset)) |
b34976b6 | 5165 | return FALSE; |
252b5132 RH |
5166 | break; |
5167 | } | |
5168 | } | |
f21f3fe0 | 5169 | |
b34976b6 | 5170 | return TRUE; |
252b5132 RH |
5171 | } |
5172 | ||
3c9458e9 NC |
5173 | /* Treat mapping symbols as special target symbols. */ |
5174 | ||
5175 | static bfd_boolean | |
5176 | elf32_arm_is_target_special_symbol (bfd * abfd ATTRIBUTE_UNUSED, asymbol * sym) | |
5177 | { | |
05ea83ed | 5178 | return bfd_is_arm_mapping_symbol_name (sym->name); |
3c9458e9 NC |
5179 | } |
5180 | ||
0367ecfb NC |
5181 | /* This is a copy of elf_find_function() from elf.c except that |
5182 | ARM mapping symbols are ignored when looking for function names | |
5183 | and STT_ARM_TFUNC is considered to a function type. */ | |
252b5132 | 5184 | |
0367ecfb NC |
5185 | static bfd_boolean |
5186 | arm_elf_find_function (bfd * abfd ATTRIBUTE_UNUSED, | |
5187 | asection * section, | |
5188 | asymbol ** symbols, | |
5189 | bfd_vma offset, | |
5190 | const char ** filename_ptr, | |
5191 | const char ** functionname_ptr) | |
5192 | { | |
5193 | const char * filename = NULL; | |
5194 | asymbol * func = NULL; | |
5195 | bfd_vma low_func = 0; | |
5196 | asymbol ** p; | |
252b5132 RH |
5197 | |
5198 | for (p = symbols; *p != NULL; p++) | |
5199 | { | |
5200 | elf_symbol_type *q; | |
5201 | ||
5202 | q = (elf_symbol_type *) *p; | |
5203 | ||
252b5132 RH |
5204 | switch (ELF_ST_TYPE (q->internal_elf_sym.st_info)) |
5205 | { | |
5206 | default: | |
5207 | break; | |
5208 | case STT_FILE: | |
5209 | filename = bfd_asymbol_name (&q->symbol); | |
5210 | break; | |
252b5132 RH |
5211 | case STT_FUNC: |
5212 | case STT_ARM_TFUNC: | |
9d2da7ca | 5213 | case STT_NOTYPE: |
0367ecfb NC |
5214 | /* Skip $a and $t symbols. */ |
5215 | if ((q->symbol.flags & BSF_LOCAL) | |
05ea83ed | 5216 | && bfd_is_arm_mapping_symbol_name (q->symbol.name)) |
0367ecfb NC |
5217 | continue; |
5218 | /* Fall through. */ | |
6b40fcba | 5219 | if (bfd_get_section (&q->symbol) == section |
252b5132 RH |
5220 | && q->symbol.value >= low_func |
5221 | && q->symbol.value <= offset) | |
5222 | { | |
5223 | func = (asymbol *) q; | |
5224 | low_func = q->symbol.value; | |
5225 | } | |
5226 | break; | |
5227 | } | |
5228 | } | |
5229 | ||
5230 | if (func == NULL) | |
b34976b6 | 5231 | return FALSE; |
252b5132 | 5232 | |
0367ecfb NC |
5233 | if (filename_ptr) |
5234 | *filename_ptr = filename; | |
5235 | if (functionname_ptr) | |
5236 | *functionname_ptr = bfd_asymbol_name (func); | |
5237 | ||
5238 | return TRUE; | |
5239 | } | |
5240 | ||
5241 | ||
5242 | /* Find the nearest line to a particular section and offset, for error | |
5243 | reporting. This code is a duplicate of the code in elf.c, except | |
5244 | that it uses arm_elf_find_function. */ | |
5245 | ||
5246 | static bfd_boolean | |
5247 | elf32_arm_find_nearest_line (bfd * abfd, | |
5248 | asection * section, | |
5249 | asymbol ** symbols, | |
5250 | bfd_vma offset, | |
5251 | const char ** filename_ptr, | |
5252 | const char ** functionname_ptr, | |
5253 | unsigned int * line_ptr) | |
5254 | { | |
5255 | bfd_boolean found = FALSE; | |
5256 | ||
5257 | /* We skip _bfd_dwarf1_find_nearest_line since no known ARM toolchain uses it. */ | |
5258 | ||
5259 | if (_bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset, | |
5260 | filename_ptr, functionname_ptr, | |
5261 | line_ptr, 0, | |
5262 | & elf_tdata (abfd)->dwarf2_find_line_info)) | |
5263 | { | |
5264 | if (!*functionname_ptr) | |
5265 | arm_elf_find_function (abfd, section, symbols, offset, | |
5266 | *filename_ptr ? NULL : filename_ptr, | |
5267 | functionname_ptr); | |
f21f3fe0 | 5268 | |
0367ecfb NC |
5269 | return TRUE; |
5270 | } | |
5271 | ||
5272 | if (! _bfd_stab_section_find_nearest_line (abfd, symbols, section, offset, | |
5273 | & found, filename_ptr, | |
5274 | functionname_ptr, line_ptr, | |
5275 | & elf_tdata (abfd)->line_info)) | |
5276 | return FALSE; | |
5277 | ||
5278 | if (found && (*functionname_ptr || *line_ptr)) | |
5279 | return TRUE; | |
5280 | ||
5281 | if (symbols == NULL) | |
5282 | return FALSE; | |
5283 | ||
5284 | if (! arm_elf_find_function (abfd, section, symbols, offset, | |
5285 | filename_ptr, functionname_ptr)) | |
5286 | return FALSE; | |
5287 | ||
5288 | *line_ptr = 0; | |
b34976b6 | 5289 | return TRUE; |
252b5132 RH |
5290 | } |
5291 | ||
5292 | /* Adjust a symbol defined by a dynamic object and referenced by a | |
5293 | regular object. The current definition is in some section of the | |
5294 | dynamic object, but we're not including those sections. We have to | |
5295 | change the definition to something the rest of the link can | |
5296 | understand. */ | |
5297 | ||
b34976b6 | 5298 | static bfd_boolean |
57e8b36a NC |
5299 | elf32_arm_adjust_dynamic_symbol (struct bfd_link_info * info, |
5300 | struct elf_link_hash_entry * h) | |
252b5132 RH |
5301 | { |
5302 | bfd * dynobj; | |
5303 | asection * s; | |
5304 | unsigned int power_of_two; | |
b7693d02 | 5305 | struct elf32_arm_link_hash_entry * eh; |
67687978 | 5306 | struct elf32_arm_link_hash_table *globals; |
252b5132 | 5307 | |
67687978 | 5308 | globals = elf32_arm_hash_table (info); |
252b5132 RH |
5309 | dynobj = elf_hash_table (info)->dynobj; |
5310 | ||
5311 | /* Make sure we know what is going on here. */ | |
5312 | BFD_ASSERT (dynobj != NULL | |
f5385ebf | 5313 | && (h->needs_plt |
f6e332e6 | 5314 | || h->u.weakdef != NULL |
f5385ebf AM |
5315 | || (h->def_dynamic |
5316 | && h->ref_regular | |
5317 | && !h->def_regular))); | |
252b5132 | 5318 | |
b7693d02 DJ |
5319 | eh = (struct elf32_arm_link_hash_entry *) h; |
5320 | ||
252b5132 RH |
5321 | /* If this is a function, put it in the procedure linkage table. We |
5322 | will fill in the contents of the procedure linkage table later, | |
5323 | when we know the address of the .got section. */ | |
b7693d02 | 5324 | if (h->type == STT_FUNC || h->type == STT_ARM_TFUNC |
f5385ebf | 5325 | || h->needs_plt) |
252b5132 | 5326 | { |
5e681ec4 PB |
5327 | if (h->plt.refcount <= 0 |
5328 | || SYMBOL_CALLS_LOCAL (info, h) | |
5329 | || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT | |
5330 | && h->root.type == bfd_link_hash_undefweak)) | |
252b5132 RH |
5331 | { |
5332 | /* This case can occur if we saw a PLT32 reloc in an input | |
5e681ec4 PB |
5333 | file, but the symbol was never referred to by a dynamic |
5334 | object, or if all references were garbage collected. In | |
5335 | such a case, we don't actually need to build a procedure | |
5336 | linkage table, and we can just do a PC24 reloc instead. */ | |
5337 | h->plt.offset = (bfd_vma) -1; | |
b7693d02 | 5338 | eh->plt_thumb_refcount = 0; |
f5385ebf | 5339 | h->needs_plt = 0; |
252b5132 RH |
5340 | } |
5341 | ||
b34976b6 | 5342 | return TRUE; |
252b5132 | 5343 | } |
5e681ec4 | 5344 | else |
b7693d02 DJ |
5345 | { |
5346 | /* It's possible that we incorrectly decided a .plt reloc was | |
5347 | needed for an R_ARM_PC24 or similar reloc to a non-function sym | |
5348 | in check_relocs. We can't decide accurately between function | |
5349 | and non-function syms in check-relocs; Objects loaded later in | |
5350 | the link may change h->type. So fix it now. */ | |
5351 | h->plt.offset = (bfd_vma) -1; | |
5352 | eh->plt_thumb_refcount = 0; | |
5353 | } | |
252b5132 RH |
5354 | |
5355 | /* If this is a weak symbol, and there is a real definition, the | |
5356 | processor independent code will have arranged for us to see the | |
5357 | real definition first, and we can just use the same value. */ | |
f6e332e6 | 5358 | if (h->u.weakdef != NULL) |
252b5132 | 5359 | { |
f6e332e6 AM |
5360 | BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined |
5361 | || h->u.weakdef->root.type == bfd_link_hash_defweak); | |
5362 | h->root.u.def.section = h->u.weakdef->root.u.def.section; | |
5363 | h->root.u.def.value = h->u.weakdef->root.u.def.value; | |
b34976b6 | 5364 | return TRUE; |
252b5132 RH |
5365 | } |
5366 | ||
ba93b8ac DJ |
5367 | /* If there are no non-GOT references, we do not need a copy |
5368 | relocation. */ | |
5369 | if (!h->non_got_ref) | |
5370 | return TRUE; | |
5371 | ||
252b5132 RH |
5372 | /* This is a reference to a symbol defined by a dynamic object which |
5373 | is not a function. */ | |
5374 | ||
5375 | /* If we are creating a shared library, we must presume that the | |
5376 | only references to the symbol are via the global offset table. | |
5377 | For such cases we need not do anything here; the relocations will | |
67687978 PB |
5378 | be handled correctly by relocate_section. Relocatable executables |
5379 | can reference data in shared objects directly, so we don't need to | |
5380 | do anything here. */ | |
5381 | if (info->shared || globals->root.is_relocatable_executable) | |
b34976b6 | 5382 | return TRUE; |
252b5132 RH |
5383 | |
5384 | /* We must allocate the symbol in our .dynbss section, which will | |
5385 | become part of the .bss section of the executable. There will be | |
5386 | an entry for this symbol in the .dynsym section. The dynamic | |
5387 | object will contain position independent code, so all references | |
5388 | from the dynamic object to this symbol will go through the global | |
5389 | offset table. The dynamic linker will use the .dynsym entry to | |
5390 | determine the address it must put in the global offset table, so | |
5391 | both the dynamic object and the regular object will refer to the | |
5392 | same memory location for the variable. */ | |
252b5132 RH |
5393 | s = bfd_get_section_by_name (dynobj, ".dynbss"); |
5394 | BFD_ASSERT (s != NULL); | |
5395 | ||
5396 | /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to | |
5397 | copy the initial value out of the dynamic object and into the | |
5398 | runtime process image. We need to remember the offset into the | |
5399 | .rel.bss section we are going to use. */ | |
5400 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0) | |
5401 | { | |
5402 | asection *srel; | |
5403 | ||
5404 | srel = bfd_get_section_by_name (dynobj, ".rel.bss"); | |
5405 | BFD_ASSERT (srel != NULL); | |
eea6121a | 5406 | srel->size += sizeof (Elf32_External_Rel); |
f5385ebf | 5407 | h->needs_copy = 1; |
252b5132 RH |
5408 | } |
5409 | ||
5410 | /* We need to figure out the alignment required for this symbol. I | |
5411 | have no idea how ELF linkers handle this. */ | |
5412 | power_of_two = bfd_log2 (h->size); | |
5413 | if (power_of_two > 3) | |
5414 | power_of_two = 3; | |
5415 | ||
5416 | /* Apply the required alignment. */ | |
eea6121a | 5417 | s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two)); |
252b5132 RH |
5418 | if (power_of_two > bfd_get_section_alignment (dynobj, s)) |
5419 | { | |
5420 | if (! bfd_set_section_alignment (dynobj, s, power_of_two)) | |
b34976b6 | 5421 | return FALSE; |
252b5132 RH |
5422 | } |
5423 | ||
5424 | /* Define the symbol as being at this point in the section. */ | |
5425 | h->root.u.def.section = s; | |
eea6121a | 5426 | h->root.u.def.value = s->size; |
252b5132 RH |
5427 | |
5428 | /* Increment the section size to make room for the symbol. */ | |
eea6121a | 5429 | s->size += h->size; |
252b5132 | 5430 | |
b34976b6 | 5431 | return TRUE; |
252b5132 RH |
5432 | } |
5433 | ||
5e681ec4 PB |
5434 | /* Allocate space in .plt, .got and associated reloc sections for |
5435 | dynamic relocs. */ | |
5436 | ||
5437 | static bfd_boolean | |
57e8b36a | 5438 | allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf) |
5e681ec4 PB |
5439 | { |
5440 | struct bfd_link_info *info; | |
5441 | struct elf32_arm_link_hash_table *htab; | |
5442 | struct elf32_arm_link_hash_entry *eh; | |
5443 | struct elf32_arm_relocs_copied *p; | |
5444 | ||
b7693d02 DJ |
5445 | eh = (struct elf32_arm_link_hash_entry *) h; |
5446 | ||
5e681ec4 PB |
5447 | if (h->root.type == bfd_link_hash_indirect) |
5448 | return TRUE; | |
5449 | ||
5450 | if (h->root.type == bfd_link_hash_warning) | |
5451 | /* When warning symbols are created, they **replace** the "real" | |
5452 | entry in the hash table, thus we never get to see the real | |
5453 | symbol in a hash traversal. So look at it now. */ | |
5454 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
5455 | ||
5456 | info = (struct bfd_link_info *) inf; | |
5457 | htab = elf32_arm_hash_table (info); | |
5458 | ||
5459 | if (htab->root.dynamic_sections_created | |
5460 | && h->plt.refcount > 0) | |
5461 | { | |
5462 | /* Make sure this symbol is output as a dynamic symbol. | |
5463 | Undefined weak syms won't yet be marked as dynamic. */ | |
5464 | if (h->dynindx == -1 | |
f5385ebf | 5465 | && !h->forced_local) |
5e681ec4 | 5466 | { |
c152c796 | 5467 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
5e681ec4 PB |
5468 | return FALSE; |
5469 | } | |
5470 | ||
5471 | if (info->shared | |
7359ea65 | 5472 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h)) |
5e681ec4 PB |
5473 | { |
5474 | asection *s = htab->splt; | |
5475 | ||
5476 | /* If this is the first .plt entry, make room for the special | |
5477 | first entry. */ | |
eea6121a | 5478 | if (s->size == 0) |
e5a52504 | 5479 | s->size += htab->plt_header_size; |
5e681ec4 | 5480 | |
eea6121a | 5481 | h->plt.offset = s->size; |
5e681ec4 | 5482 | |
b7693d02 DJ |
5483 | /* If we will insert a Thumb trampoline before this PLT, leave room |
5484 | for it. */ | |
33bfe774 | 5485 | if (!htab->use_blx && eh->plt_thumb_refcount > 0) |
b7693d02 DJ |
5486 | { |
5487 | h->plt.offset += PLT_THUMB_STUB_SIZE; | |
5488 | s->size += PLT_THUMB_STUB_SIZE; | |
5489 | } | |
5490 | ||
5e681ec4 PB |
5491 | /* If this symbol is not defined in a regular file, and we are |
5492 | not generating a shared library, then set the symbol to this | |
5493 | location in the .plt. This is required to make function | |
5494 | pointers compare as equal between the normal executable and | |
5495 | the shared library. */ | |
5496 | if (! info->shared | |
f5385ebf | 5497 | && !h->def_regular) |
5e681ec4 PB |
5498 | { |
5499 | h->root.u.def.section = s; | |
5500 | h->root.u.def.value = h->plt.offset; | |
b7693d02 DJ |
5501 | |
5502 | /* Make sure the function is not marked as Thumb, in case | |
5503 | it is the target of an ABS32 relocation, which will | |
5504 | point to the PLT entry. */ | |
5505 | if (ELF_ST_TYPE (h->type) == STT_ARM_TFUNC) | |
5506 | h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC); | |
5e681ec4 PB |
5507 | } |
5508 | ||
5509 | /* Make room for this entry. */ | |
e5a52504 | 5510 | s->size += htab->plt_entry_size; |
5e681ec4 | 5511 | |
e5a52504 | 5512 | if (!htab->symbian_p) |
b7693d02 DJ |
5513 | { |
5514 | /* We also need to make an entry in the .got.plt section, which | |
5515 | will be placed in the .got section by the linker script. */ | |
5516 | eh->plt_got_offset = htab->sgotplt->size; | |
5517 | htab->sgotplt->size += 4; | |
5518 | } | |
5e681ec4 PB |
5519 | |
5520 | /* We also need to make an entry in the .rel.plt section. */ | |
eea6121a | 5521 | htab->srelplt->size += sizeof (Elf32_External_Rel); |
5e681ec4 PB |
5522 | } |
5523 | else | |
5524 | { | |
5525 | h->plt.offset = (bfd_vma) -1; | |
f5385ebf | 5526 | h->needs_plt = 0; |
5e681ec4 PB |
5527 | } |
5528 | } | |
5529 | else | |
5530 | { | |
5531 | h->plt.offset = (bfd_vma) -1; | |
f5385ebf | 5532 | h->needs_plt = 0; |
5e681ec4 PB |
5533 | } |
5534 | ||
5535 | if (h->got.refcount > 0) | |
5536 | { | |
5537 | asection *s; | |
5538 | bfd_boolean dyn; | |
ba93b8ac DJ |
5539 | int tls_type = elf32_arm_hash_entry (h)->tls_type; |
5540 | int indx; | |
5e681ec4 PB |
5541 | |
5542 | /* Make sure this symbol is output as a dynamic symbol. | |
5543 | Undefined weak syms won't yet be marked as dynamic. */ | |
5544 | if (h->dynindx == -1 | |
f5385ebf | 5545 | && !h->forced_local) |
5e681ec4 | 5546 | { |
c152c796 | 5547 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
5e681ec4 PB |
5548 | return FALSE; |
5549 | } | |
5550 | ||
e5a52504 MM |
5551 | if (!htab->symbian_p) |
5552 | { | |
5553 | s = htab->sgot; | |
5554 | h->got.offset = s->size; | |
ba93b8ac DJ |
5555 | |
5556 | if (tls_type == GOT_UNKNOWN) | |
5557 | abort (); | |
5558 | ||
5559 | if (tls_type == GOT_NORMAL) | |
5560 | /* Non-TLS symbols need one GOT slot. */ | |
5561 | s->size += 4; | |
5562 | else | |
5563 | { | |
5564 | if (tls_type & GOT_TLS_GD) | |
5565 | /* R_ARM_TLS_GD32 needs 2 consecutive GOT slots. */ | |
5566 | s->size += 8; | |
5567 | if (tls_type & GOT_TLS_IE) | |
5568 | /* R_ARM_TLS_IE32 needs one GOT slot. */ | |
5569 | s->size += 4; | |
5570 | } | |
5571 | ||
e5a52504 | 5572 | dyn = htab->root.dynamic_sections_created; |
ba93b8ac DJ |
5573 | |
5574 | indx = 0; | |
5575 | if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) | |
5576 | && (!info->shared | |
5577 | || !SYMBOL_REFERENCES_LOCAL (info, h))) | |
5578 | indx = h->dynindx; | |
5579 | ||
5580 | if (tls_type != GOT_NORMAL | |
5581 | && (info->shared || indx != 0) | |
5582 | && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
5583 | || h->root.type != bfd_link_hash_undefweak)) | |
5584 | { | |
5585 | if (tls_type & GOT_TLS_IE) | |
5586 | htab->srelgot->size += sizeof (Elf32_External_Rel); | |
5587 | ||
5588 | if (tls_type & GOT_TLS_GD) | |
5589 | htab->srelgot->size += sizeof (Elf32_External_Rel); | |
5590 | ||
5591 | if ((tls_type & GOT_TLS_GD) && indx != 0) | |
5592 | htab->srelgot->size += sizeof (Elf32_External_Rel); | |
5593 | } | |
5594 | else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
5595 | || h->root.type != bfd_link_hash_undefweak) | |
5596 | && (info->shared | |
5597 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h))) | |
e5a52504 MM |
5598 | htab->srelgot->size += sizeof (Elf32_External_Rel); |
5599 | } | |
5e681ec4 PB |
5600 | } |
5601 | else | |
5602 | h->got.offset = (bfd_vma) -1; | |
5603 | ||
5e681ec4 PB |
5604 | if (eh->relocs_copied == NULL) |
5605 | return TRUE; | |
5606 | ||
5607 | /* In the shared -Bsymbolic case, discard space allocated for | |
5608 | dynamic pc-relative relocs against symbols which turn out to be | |
5609 | defined in regular objects. For the normal shared case, discard | |
5610 | space for pc-relative relocs that have become local due to symbol | |
5611 | visibility changes. */ | |
5612 | ||
67687978 | 5613 | if (info->shared || htab->root.is_relocatable_executable) |
5e681ec4 | 5614 | { |
ba93b8ac DJ |
5615 | /* The only reloc that uses pc_count is R_ARM_REL32, which will |
5616 | appear on something like ".long foo - .". We want calls to | |
5617 | protected symbols to resolve directly to the function rather | |
5618 | than going via the plt. If people want function pointer | |
5619 | comparisons to work as expected then they should avoid | |
5620 | writing assembly like ".long foo - .". */ | |
5621 | if (SYMBOL_CALLS_LOCAL (info, h)) | |
5622 | { | |
5623 | struct elf32_arm_relocs_copied **pp; | |
5624 | ||
5625 | for (pp = &eh->relocs_copied; (p = *pp) != NULL; ) | |
5626 | { | |
5627 | p->count -= p->pc_count; | |
5628 | p->pc_count = 0; | |
5629 | if (p->count == 0) | |
5630 | *pp = p->next; | |
5631 | else | |
5632 | pp = &p->next; | |
5633 | } | |
5634 | } | |
5635 | ||
5636 | /* Also discard relocs on undefined weak syms with non-default | |
7359ea65 | 5637 | visibility. */ |
5e681ec4 PB |
5638 | if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT |
5639 | && h->root.type == bfd_link_hash_undefweak) | |
5640 | eh->relocs_copied = NULL; | |
67687978 PB |
5641 | else if (htab->root.is_relocatable_executable && h->dynindx == -1 |
5642 | && h->root.type == bfd_link_hash_new) | |
5643 | { | |
5644 | /* Output absolute symbols so that we can create relocations | |
5645 | against them. For normal symbols we output a relocation | |
5646 | against the section that contains them. */ | |
5647 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) | |
5648 | return FALSE; | |
5649 | } | |
5650 | ||
5e681ec4 PB |
5651 | } |
5652 | else | |
5653 | { | |
5654 | /* For the non-shared case, discard space for relocs against | |
5655 | symbols which turn out to need copy relocs or are not | |
5656 | dynamic. */ | |
5657 | ||
f5385ebf AM |
5658 | if (!h->non_got_ref |
5659 | && ((h->def_dynamic | |
5660 | && !h->def_regular) | |
5e681ec4 PB |
5661 | || (htab->root.dynamic_sections_created |
5662 | && (h->root.type == bfd_link_hash_undefweak | |
5663 | || h->root.type == bfd_link_hash_undefined)))) | |
5664 | { | |
5665 | /* Make sure this symbol is output as a dynamic symbol. | |
5666 | Undefined weak syms won't yet be marked as dynamic. */ | |
5667 | if (h->dynindx == -1 | |
f5385ebf | 5668 | && !h->forced_local) |
5e681ec4 | 5669 | { |
c152c796 | 5670 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
5e681ec4 PB |
5671 | return FALSE; |
5672 | } | |
5673 | ||
5674 | /* If that succeeded, we know we'll be keeping all the | |
5675 | relocs. */ | |
5676 | if (h->dynindx != -1) | |
5677 | goto keep; | |
5678 | } | |
5679 | ||
5680 | eh->relocs_copied = NULL; | |
5681 | ||
5682 | keep: ; | |
5683 | } | |
5684 | ||
5685 | /* Finally, allocate space. */ | |
5686 | for (p = eh->relocs_copied; p != NULL; p = p->next) | |
5687 | { | |
5688 | asection *sreloc = elf_section_data (p->section)->sreloc; | |
eea6121a | 5689 | sreloc->size += p->count * sizeof (Elf32_External_Rel); |
5e681ec4 PB |
5690 | } |
5691 | ||
5692 | return TRUE; | |
5693 | } | |
5694 | ||
08d1f311 DJ |
5695 | /* Find any dynamic relocs that apply to read-only sections. */ |
5696 | ||
5697 | static bfd_boolean | |
5698 | elf32_arm_readonly_dynrelocs (struct elf_link_hash_entry *h, PTR inf) | |
5699 | { | |
5700 | struct elf32_arm_link_hash_entry *eh; | |
5701 | struct elf32_arm_relocs_copied *p; | |
5702 | ||
5703 | if (h->root.type == bfd_link_hash_warning) | |
5704 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
5705 | ||
5706 | eh = (struct elf32_arm_link_hash_entry *) h; | |
5707 | for (p = eh->relocs_copied; p != NULL; p = p->next) | |
5708 | { | |
5709 | asection *s = p->section; | |
5710 | ||
5711 | if (s != NULL && (s->flags & SEC_READONLY) != 0) | |
5712 | { | |
5713 | struct bfd_link_info *info = (struct bfd_link_info *) inf; | |
5714 | ||
5715 | info->flags |= DF_TEXTREL; | |
5716 | ||
5717 | /* Not an error, just cut short the traversal. */ | |
5718 | return FALSE; | |
5719 | } | |
5720 | } | |
5721 | return TRUE; | |
5722 | } | |
5723 | ||
252b5132 RH |
5724 | /* Set the sizes of the dynamic sections. */ |
5725 | ||
b34976b6 | 5726 | static bfd_boolean |
57e8b36a NC |
5727 | elf32_arm_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED, |
5728 | struct bfd_link_info * info) | |
252b5132 RH |
5729 | { |
5730 | bfd * dynobj; | |
5731 | asection * s; | |
b34976b6 AM |
5732 | bfd_boolean plt; |
5733 | bfd_boolean relocs; | |
5e681ec4 PB |
5734 | bfd *ibfd; |
5735 | struct elf32_arm_link_hash_table *htab; | |
252b5132 | 5736 | |
5e681ec4 | 5737 | htab = elf32_arm_hash_table (info); |
252b5132 RH |
5738 | dynobj = elf_hash_table (info)->dynobj; |
5739 | BFD_ASSERT (dynobj != NULL); | |
5740 | ||
5741 | if (elf_hash_table (info)->dynamic_sections_created) | |
5742 | { | |
5743 | /* Set the contents of the .interp section to the interpreter. */ | |
893c4fe2 | 5744 | if (info->executable) |
252b5132 RH |
5745 | { |
5746 | s = bfd_get_section_by_name (dynobj, ".interp"); | |
5747 | BFD_ASSERT (s != NULL); | |
eea6121a | 5748 | s->size = sizeof ELF_DYNAMIC_INTERPRETER; |
252b5132 RH |
5749 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; |
5750 | } | |
5751 | } | |
5e681ec4 PB |
5752 | |
5753 | /* Set up .got offsets for local syms, and space for local dynamic | |
5754 | relocs. */ | |
5755 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) | |
252b5132 | 5756 | { |
5e681ec4 PB |
5757 | bfd_signed_vma *local_got; |
5758 | bfd_signed_vma *end_local_got; | |
5759 | char *local_tls_type; | |
5760 | bfd_size_type locsymcount; | |
5761 | Elf_Internal_Shdr *symtab_hdr; | |
5762 | asection *srel; | |
5763 | ||
5764 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour) | |
5765 | continue; | |
5766 | ||
5767 | for (s = ibfd->sections; s != NULL; s = s->next) | |
5768 | { | |
5769 | struct elf32_arm_relocs_copied *p; | |
5770 | ||
5771 | for (p = *((struct elf32_arm_relocs_copied **) | |
5772 | &elf_section_data (s)->local_dynrel); | |
5773 | p != NULL; | |
5774 | p = p->next) | |
5775 | { | |
5776 | if (!bfd_is_abs_section (p->section) | |
5777 | && bfd_is_abs_section (p->section->output_section)) | |
5778 | { | |
5779 | /* Input section has been discarded, either because | |
5780 | it is a copy of a linkonce section or due to | |
5781 | linker script /DISCARD/, so we'll be discarding | |
5782 | the relocs too. */ | |
5783 | } | |
5784 | else if (p->count != 0) | |
5785 | { | |
5786 | srel = elf_section_data (p->section)->sreloc; | |
eea6121a | 5787 | srel->size += p->count * sizeof (Elf32_External_Rel); |
5e681ec4 PB |
5788 | if ((p->section->output_section->flags & SEC_READONLY) != 0) |
5789 | info->flags |= DF_TEXTREL; | |
5790 | } | |
5791 | } | |
5792 | } | |
5793 | ||
5794 | local_got = elf_local_got_refcounts (ibfd); | |
5795 | if (!local_got) | |
5796 | continue; | |
5797 | ||
5798 | symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; | |
5799 | locsymcount = symtab_hdr->sh_info; | |
5800 | end_local_got = local_got + locsymcount; | |
ba93b8ac | 5801 | local_tls_type = elf32_arm_local_got_tls_type (ibfd); |
5e681ec4 PB |
5802 | s = htab->sgot; |
5803 | srel = htab->srelgot; | |
5804 | for (; local_got < end_local_got; ++local_got, ++local_tls_type) | |
5805 | { | |
5806 | if (*local_got > 0) | |
5807 | { | |
eea6121a | 5808 | *local_got = s->size; |
ba93b8ac DJ |
5809 | if (*local_tls_type & GOT_TLS_GD) |
5810 | /* TLS_GD relocs need an 8-byte structure in the GOT. */ | |
5811 | s->size += 8; | |
5812 | if (*local_tls_type & GOT_TLS_IE) | |
5813 | s->size += 4; | |
5814 | if (*local_tls_type == GOT_NORMAL) | |
5815 | s->size += 4; | |
5816 | ||
5817 | if (info->shared || *local_tls_type == GOT_TLS_GD) | |
eea6121a | 5818 | srel->size += sizeof (Elf32_External_Rel); |
5e681ec4 PB |
5819 | } |
5820 | else | |
5821 | *local_got = (bfd_vma) -1; | |
5822 | } | |
252b5132 RH |
5823 | } |
5824 | ||
ba93b8ac DJ |
5825 | if (htab->tls_ldm_got.refcount > 0) |
5826 | { | |
5827 | /* Allocate two GOT entries and one dynamic relocation (if necessary) | |
5828 | for R_ARM_TLS_LDM32 relocations. */ | |
5829 | htab->tls_ldm_got.offset = htab->sgot->size; | |
5830 | htab->sgot->size += 8; | |
5831 | if (info->shared) | |
5832 | htab->srelgot->size += sizeof (Elf32_External_Rel); | |
5833 | } | |
5834 | else | |
5835 | htab->tls_ldm_got.offset = -1; | |
5836 | ||
5e681ec4 PB |
5837 | /* Allocate global sym .plt and .got entries, and space for global |
5838 | sym dynamic relocs. */ | |
57e8b36a | 5839 | elf_link_hash_traverse (& htab->root, allocate_dynrelocs, info); |
252b5132 RH |
5840 | |
5841 | /* The check_relocs and adjust_dynamic_symbol entry points have | |
5842 | determined the sizes of the various dynamic sections. Allocate | |
5843 | memory for them. */ | |
b34976b6 AM |
5844 | plt = FALSE; |
5845 | relocs = FALSE; | |
252b5132 RH |
5846 | for (s = dynobj->sections; s != NULL; s = s->next) |
5847 | { | |
5848 | const char * name; | |
b34976b6 | 5849 | bfd_boolean strip; |
252b5132 RH |
5850 | |
5851 | if ((s->flags & SEC_LINKER_CREATED) == 0) | |
5852 | continue; | |
5853 | ||
5854 | /* It's OK to base decisions on the section name, because none | |
5855 | of the dynobj section names depend upon the input files. */ | |
5856 | name = bfd_get_section_name (dynobj, s); | |
5857 | ||
b34976b6 | 5858 | strip = FALSE; |
252b5132 | 5859 | |
24a1ba0f | 5860 | if (strcmp (name, ".plt") == 0) |
252b5132 | 5861 | { |
eea6121a | 5862 | if (s->size == 0) |
252b5132 RH |
5863 | { |
5864 | /* Strip this section if we don't need it; see the | |
5865 | comment below. */ | |
b34976b6 | 5866 | strip = TRUE; |
252b5132 RH |
5867 | } |
5868 | else | |
5869 | { | |
5870 | /* Remember whether there is a PLT. */ | |
b34976b6 | 5871 | plt = TRUE; |
252b5132 RH |
5872 | } |
5873 | } | |
5874 | else if (strncmp (name, ".rel", 4) == 0) | |
5875 | { | |
eea6121a | 5876 | if (s->size == 0) |
252b5132 RH |
5877 | { |
5878 | /* If we don't need this section, strip it from the | |
5879 | output file. This is mostly to handle .rel.bss and | |
5880 | .rel.plt. We must create both sections in | |
5881 | create_dynamic_sections, because they must be created | |
5882 | before the linker maps input sections to output | |
5883 | sections. The linker does that before | |
5884 | adjust_dynamic_symbol is called, and it is that | |
5885 | function which decides whether anything needs to go | |
5886 | into these sections. */ | |
b34976b6 | 5887 | strip = TRUE; |
252b5132 RH |
5888 | } |
5889 | else | |
5890 | { | |
252b5132 RH |
5891 | /* Remember whether there are any reloc sections other |
5892 | than .rel.plt. */ | |
5893 | if (strcmp (name, ".rel.plt") != 0) | |
b34976b6 | 5894 | relocs = TRUE; |
252b5132 RH |
5895 | |
5896 | /* We use the reloc_count field as a counter if we need | |
5897 | to copy relocs into the output file. */ | |
5898 | s->reloc_count = 0; | |
5899 | } | |
5900 | } | |
5901 | else if (strncmp (name, ".got", 4) != 0) | |
5902 | { | |
5903 | /* It's not one of our sections, so don't allocate space. */ | |
5904 | continue; | |
5905 | } | |
5906 | ||
5907 | if (strip) | |
5908 | { | |
8423293d | 5909 | s->flags |= SEC_EXCLUDE; |
252b5132 RH |
5910 | continue; |
5911 | } | |
5912 | ||
5913 | /* Allocate memory for the section contents. */ | |
eea6121a AM |
5914 | s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size); |
5915 | if (s->contents == NULL && s->size != 0) | |
b34976b6 | 5916 | return FALSE; |
252b5132 RH |
5917 | } |
5918 | ||
5919 | if (elf_hash_table (info)->dynamic_sections_created) | |
5920 | { | |
5921 | /* Add some entries to the .dynamic section. We fill in the | |
5922 | values later, in elf32_arm_finish_dynamic_sections, but we | |
5923 | must add the entries now so that we get the correct size for | |
5924 | the .dynamic section. The DT_DEBUG entry is filled in by the | |
5925 | dynamic linker and used by the debugger. */ | |
dc810e39 | 5926 | #define add_dynamic_entry(TAG, VAL) \ |
5a580b3a | 5927 | _bfd_elf_add_dynamic_entry (info, TAG, VAL) |
dc810e39 AM |
5928 | |
5929 | if (!info->shared) | |
252b5132 | 5930 | { |
dc810e39 | 5931 | if (!add_dynamic_entry (DT_DEBUG, 0)) |
b34976b6 | 5932 | return FALSE; |
252b5132 RH |
5933 | } |
5934 | ||
5935 | if (plt) | |
5936 | { | |
dc810e39 AM |
5937 | if ( !add_dynamic_entry (DT_PLTGOT, 0) |
5938 | || !add_dynamic_entry (DT_PLTRELSZ, 0) | |
5939 | || !add_dynamic_entry (DT_PLTREL, DT_REL) | |
5940 | || !add_dynamic_entry (DT_JMPREL, 0)) | |
b34976b6 | 5941 | return FALSE; |
252b5132 RH |
5942 | } |
5943 | ||
5944 | if (relocs) | |
5945 | { | |
dc810e39 AM |
5946 | if ( !add_dynamic_entry (DT_REL, 0) |
5947 | || !add_dynamic_entry (DT_RELSZ, 0) | |
5948 | || !add_dynamic_entry (DT_RELENT, sizeof (Elf32_External_Rel))) | |
b34976b6 | 5949 | return FALSE; |
252b5132 RH |
5950 | } |
5951 | ||
08d1f311 DJ |
5952 | /* If any dynamic relocs apply to a read-only section, |
5953 | then we need a DT_TEXTREL entry. */ | |
5954 | if ((info->flags & DF_TEXTREL) == 0) | |
5955 | elf_link_hash_traverse (&htab->root, elf32_arm_readonly_dynrelocs, | |
5956 | (PTR) info); | |
5957 | ||
99e4ae17 | 5958 | if ((info->flags & DF_TEXTREL) != 0) |
252b5132 | 5959 | { |
dc810e39 | 5960 | if (!add_dynamic_entry (DT_TEXTREL, 0)) |
b34976b6 | 5961 | return FALSE; |
d6cf2879 | 5962 | info->flags |= DF_TEXTREL; |
252b5132 RH |
5963 | } |
5964 | } | |
dc810e39 | 5965 | #undef add_synamic_entry |
252b5132 | 5966 | |
b34976b6 | 5967 | return TRUE; |
252b5132 RH |
5968 | } |
5969 | ||
252b5132 RH |
5970 | /* Finish up dynamic symbol handling. We set the contents of various |
5971 | dynamic sections here. */ | |
5972 | ||
b34976b6 | 5973 | static bfd_boolean |
57e8b36a NC |
5974 | elf32_arm_finish_dynamic_symbol (bfd * output_bfd, struct bfd_link_info * info, |
5975 | struct elf_link_hash_entry * h, Elf_Internal_Sym * sym) | |
252b5132 RH |
5976 | { |
5977 | bfd * dynobj; | |
e5a52504 | 5978 | struct elf32_arm_link_hash_table *htab; |
b7693d02 | 5979 | struct elf32_arm_link_hash_entry *eh; |
252b5132 RH |
5980 | |
5981 | dynobj = elf_hash_table (info)->dynobj; | |
e5a52504 | 5982 | htab = elf32_arm_hash_table (info); |
b7693d02 | 5983 | eh = (struct elf32_arm_link_hash_entry *) h; |
252b5132 RH |
5984 | |
5985 | if (h->plt.offset != (bfd_vma) -1) | |
5986 | { | |
5987 | asection * splt; | |
252b5132 | 5988 | asection * srel; |
e5a52504 | 5989 | bfd_byte *loc; |
24a1ba0f | 5990 | bfd_vma plt_index; |
947216bf | 5991 | Elf_Internal_Rela rel; |
252b5132 RH |
5992 | |
5993 | /* This symbol has an entry in the procedure linkage table. Set | |
5994 | it up. */ | |
5995 | ||
5996 | BFD_ASSERT (h->dynindx != -1); | |
5997 | ||
5998 | splt = bfd_get_section_by_name (dynobj, ".plt"); | |
252b5132 | 5999 | srel = bfd_get_section_by_name (dynobj, ".rel.plt"); |
e5a52504 | 6000 | BFD_ASSERT (splt != NULL && srel != NULL); |
252b5132 | 6001 | |
e5a52504 MM |
6002 | /* Fill in the entry in the procedure linkage table. */ |
6003 | if (htab->symbian_p) | |
6004 | { | |
6005 | unsigned i; | |
6006 | for (i = 0; i < htab->plt_entry_size / 4; ++i) | |
6007 | bfd_put_32 (output_bfd, | |
6008 | elf32_arm_symbian_plt_entry[i], | |
6009 | splt->contents + h->plt.offset + 4 * i); | |
6010 | ||
6011 | /* Fill in the entry in the .rel.plt section. */ | |
2a1b9a48 MM |
6012 | rel.r_offset = (splt->output_section->vma |
6013 | + splt->output_offset | |
e5a52504 MM |
6014 | + h->plt.offset + 4 * (i - 1)); |
6015 | rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT); | |
b7693d02 DJ |
6016 | |
6017 | /* Get the index in the procedure linkage table which | |
6018 | corresponds to this symbol. This is the index of this symbol | |
6019 | in all the symbols for which we are making plt entries. The | |
6020 | first entry in the procedure linkage table is reserved. */ | |
6021 | plt_index = ((h->plt.offset - htab->plt_header_size) | |
6022 | / htab->plt_entry_size); | |
e5a52504 MM |
6023 | } |
6024 | else | |
6025 | { | |
6026 | bfd_vma got_offset; | |
6027 | bfd_vma got_displacement; | |
6028 | asection * sgot; | |
6029 | ||
6030 | sgot = bfd_get_section_by_name (dynobj, ".got.plt"); | |
6031 | BFD_ASSERT (sgot != NULL); | |
6032 | ||
b7693d02 DJ |
6033 | /* Get the offset into the .got.plt table of the entry that |
6034 | corresponds to this function. */ | |
6035 | got_offset = eh->plt_got_offset; | |
6036 | ||
6037 | /* Get the index in the procedure linkage table which | |
6038 | corresponds to this symbol. This is the index of this symbol | |
6039 | in all the symbols for which we are making plt entries. The | |
6040 | first three entries in .got.plt are reserved; after that | |
6041 | symbols appear in the same order as in .plt. */ | |
6042 | plt_index = (got_offset - 12) / 4; | |
e5a52504 MM |
6043 | |
6044 | /* Calculate the displacement between the PLT slot and the | |
b7693d02 DJ |
6045 | entry in the GOT. The eight-byte offset accounts for the |
6046 | value produced by adding to pc in the first instruction | |
6047 | of the PLT stub. */ | |
e5a52504 MM |
6048 | got_displacement = (sgot->output_section->vma |
6049 | + sgot->output_offset | |
6050 | + got_offset | |
6051 | - splt->output_section->vma | |
6052 | - splt->output_offset | |
6053 | - h->plt.offset | |
6054 | - 8); | |
5e681ec4 | 6055 | |
e5a52504 | 6056 | BFD_ASSERT ((got_displacement & 0xf0000000) == 0); |
5e681ec4 | 6057 | |
33bfe774 | 6058 | if (!htab->use_blx && eh->plt_thumb_refcount > 0) |
b7693d02 DJ |
6059 | { |
6060 | bfd_put_16 (output_bfd, elf32_arm_plt_thumb_stub[0], | |
6061 | splt->contents + h->plt.offset - 4); | |
6062 | bfd_put_16 (output_bfd, elf32_arm_plt_thumb_stub[1], | |
6063 | splt->contents + h->plt.offset - 2); | |
6064 | } | |
6065 | ||
e5a52504 MM |
6066 | bfd_put_32 (output_bfd, elf32_arm_plt_entry[0] | ((got_displacement & 0x0ff00000) >> 20), |
6067 | splt->contents + h->plt.offset + 0); | |
6068 | bfd_put_32 (output_bfd, elf32_arm_plt_entry[1] | ((got_displacement & 0x000ff000) >> 12), | |
6069 | splt->contents + h->plt.offset + 4); | |
6070 | bfd_put_32 (output_bfd, elf32_arm_plt_entry[2] | (got_displacement & 0x00000fff), | |
6071 | splt->contents + h->plt.offset + 8); | |
5e681ec4 | 6072 | #ifdef FOUR_WORD_PLT |
e5a52504 MM |
6073 | bfd_put_32 (output_bfd, elf32_arm_plt_entry[3], |
6074 | splt->contents + h->plt.offset + 12); | |
5e681ec4 | 6075 | #endif |
252b5132 | 6076 | |
e5a52504 MM |
6077 | /* Fill in the entry in the global offset table. */ |
6078 | bfd_put_32 (output_bfd, | |
6079 | (splt->output_section->vma | |
6080 | + splt->output_offset), | |
6081 | sgot->contents + got_offset); | |
6082 | ||
6083 | /* Fill in the entry in the .rel.plt section. */ | |
6084 | rel.r_offset = (sgot->output_section->vma | |
6085 | + sgot->output_offset | |
6086 | + got_offset); | |
6087 | rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_JUMP_SLOT); | |
6088 | } | |
57e8b36a | 6089 | |
947216bf AM |
6090 | loc = srel->contents + plt_index * sizeof (Elf32_External_Rel); |
6091 | bfd_elf32_swap_reloc_out (output_bfd, &rel, loc); | |
252b5132 | 6092 | |
f5385ebf | 6093 | if (!h->def_regular) |
252b5132 RH |
6094 | { |
6095 | /* Mark the symbol as undefined, rather than as defined in | |
6096 | the .plt section. Leave the value alone. */ | |
6097 | sym->st_shndx = SHN_UNDEF; | |
d982ba73 PB |
6098 | /* If the symbol is weak, we do need to clear the value. |
6099 | Otherwise, the PLT entry would provide a definition for | |
6100 | the symbol even if the symbol wasn't defined anywhere, | |
6101 | and so the symbol would never be NULL. */ | |
f5385ebf | 6102 | if (!h->ref_regular_nonweak) |
d982ba73 | 6103 | sym->st_value = 0; |
252b5132 RH |
6104 | } |
6105 | } | |
6106 | ||
ba93b8ac DJ |
6107 | if (h->got.offset != (bfd_vma) -1 |
6108 | && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_GD) == 0 | |
6109 | && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_IE) == 0) | |
252b5132 RH |
6110 | { |
6111 | asection * sgot; | |
6112 | asection * srel; | |
947216bf AM |
6113 | Elf_Internal_Rela rel; |
6114 | bfd_byte *loc; | |
252b5132 RH |
6115 | |
6116 | /* This symbol has an entry in the global offset table. Set it | |
6117 | up. */ | |
252b5132 RH |
6118 | sgot = bfd_get_section_by_name (dynobj, ".got"); |
6119 | srel = bfd_get_section_by_name (dynobj, ".rel.got"); | |
6120 | BFD_ASSERT (sgot != NULL && srel != NULL); | |
6121 | ||
6122 | rel.r_offset = (sgot->output_section->vma | |
6123 | + sgot->output_offset | |
dc810e39 | 6124 | + (h->got.offset &~ (bfd_vma) 1)); |
252b5132 | 6125 | |
5e681ec4 PB |
6126 | /* If this is a static link, or it is a -Bsymbolic link and the |
6127 | symbol is defined locally or was forced to be local because | |
6128 | of a version file, we just want to emit a RELATIVE reloc. | |
6129 | The entry in the global offset table will already have been | |
6130 | initialized in the relocate_section function. */ | |
252b5132 | 6131 | if (info->shared |
5e681ec4 PB |
6132 | && SYMBOL_REFERENCES_LOCAL (info, h)) |
6133 | { | |
6134 | BFD_ASSERT((h->got.offset & 1) != 0); | |
6135 | rel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE); | |
6136 | } | |
252b5132 RH |
6137 | else |
6138 | { | |
5e681ec4 | 6139 | BFD_ASSERT((h->got.offset & 1) == 0); |
252b5132 RH |
6140 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset); |
6141 | rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT); | |
6142 | } | |
6143 | ||
947216bf AM |
6144 | loc = srel->contents + srel->reloc_count++ * sizeof (Elf32_External_Rel); |
6145 | bfd_elf32_swap_reloc_out (output_bfd, &rel, loc); | |
252b5132 RH |
6146 | } |
6147 | ||
f5385ebf | 6148 | if (h->needs_copy) |
252b5132 RH |
6149 | { |
6150 | asection * s; | |
947216bf AM |
6151 | Elf_Internal_Rela rel; |
6152 | bfd_byte *loc; | |
252b5132 RH |
6153 | |
6154 | /* This symbol needs a copy reloc. Set it up. */ | |
252b5132 RH |
6155 | BFD_ASSERT (h->dynindx != -1 |
6156 | && (h->root.type == bfd_link_hash_defined | |
6157 | || h->root.type == bfd_link_hash_defweak)); | |
6158 | ||
6159 | s = bfd_get_section_by_name (h->root.u.def.section->owner, | |
6160 | ".rel.bss"); | |
6161 | BFD_ASSERT (s != NULL); | |
6162 | ||
6163 | rel.r_offset = (h->root.u.def.value | |
6164 | + h->root.u.def.section->output_section->vma | |
6165 | + h->root.u.def.section->output_offset); | |
6166 | rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_COPY); | |
947216bf AM |
6167 | loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rel); |
6168 | bfd_elf32_swap_reloc_out (output_bfd, &rel, loc); | |
252b5132 RH |
6169 | } |
6170 | ||
6171 | /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */ | |
6172 | if (strcmp (h->root.root.string, "_DYNAMIC") == 0 | |
6173 | || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0) | |
6174 | sym->st_shndx = SHN_ABS; | |
6175 | ||
b34976b6 | 6176 | return TRUE; |
252b5132 RH |
6177 | } |
6178 | ||
6179 | /* Finish up the dynamic sections. */ | |
6180 | ||
b34976b6 | 6181 | static bfd_boolean |
57e8b36a | 6182 | elf32_arm_finish_dynamic_sections (bfd * output_bfd, struct bfd_link_info * info) |
252b5132 RH |
6183 | { |
6184 | bfd * dynobj; | |
6185 | asection * sgot; | |
6186 | asection * sdyn; | |
6187 | ||
6188 | dynobj = elf_hash_table (info)->dynobj; | |
6189 | ||
6190 | sgot = bfd_get_section_by_name (dynobj, ".got.plt"); | |
229fcec5 | 6191 | BFD_ASSERT (elf32_arm_hash_table (info)->symbian_p || sgot != NULL); |
252b5132 RH |
6192 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); |
6193 | ||
6194 | if (elf_hash_table (info)->dynamic_sections_created) | |
6195 | { | |
6196 | asection *splt; | |
6197 | Elf32_External_Dyn *dyncon, *dynconend; | |
229fcec5 | 6198 | struct elf32_arm_link_hash_table *htab; |
252b5132 | 6199 | |
229fcec5 | 6200 | htab = elf32_arm_hash_table (info); |
252b5132 | 6201 | splt = bfd_get_section_by_name (dynobj, ".plt"); |
24a1ba0f | 6202 | BFD_ASSERT (splt != NULL && sdyn != NULL); |
252b5132 RH |
6203 | |
6204 | dyncon = (Elf32_External_Dyn *) sdyn->contents; | |
eea6121a | 6205 | dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size); |
9b485d32 | 6206 | |
252b5132 RH |
6207 | for (; dyncon < dynconend; dyncon++) |
6208 | { | |
6209 | Elf_Internal_Dyn dyn; | |
6210 | const char * name; | |
6211 | asection * s; | |
6212 | ||
6213 | bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn); | |
6214 | ||
6215 | switch (dyn.d_tag) | |
6216 | { | |
229fcec5 MM |
6217 | unsigned int type; |
6218 | ||
252b5132 RH |
6219 | default: |
6220 | break; | |
6221 | ||
229fcec5 MM |
6222 | case DT_HASH: |
6223 | name = ".hash"; | |
6224 | goto get_vma_if_bpabi; | |
6225 | case DT_STRTAB: | |
6226 | name = ".dynstr"; | |
6227 | goto get_vma_if_bpabi; | |
6228 | case DT_SYMTAB: | |
6229 | name = ".dynsym"; | |
6230 | goto get_vma_if_bpabi; | |
c0042f5d MM |
6231 | case DT_VERSYM: |
6232 | name = ".gnu.version"; | |
6233 | goto get_vma_if_bpabi; | |
6234 | case DT_VERDEF: | |
6235 | name = ".gnu.version_d"; | |
6236 | goto get_vma_if_bpabi; | |
6237 | case DT_VERNEED: | |
6238 | name = ".gnu.version_r"; | |
6239 | goto get_vma_if_bpabi; | |
6240 | ||
252b5132 RH |
6241 | case DT_PLTGOT: |
6242 | name = ".got"; | |
6243 | goto get_vma; | |
6244 | case DT_JMPREL: | |
6245 | name = ".rel.plt"; | |
6246 | get_vma: | |
6247 | s = bfd_get_section_by_name (output_bfd, name); | |
6248 | BFD_ASSERT (s != NULL); | |
229fcec5 MM |
6249 | if (!htab->symbian_p) |
6250 | dyn.d_un.d_ptr = s->vma; | |
6251 | else | |
6252 | /* In the BPABI, tags in the PT_DYNAMIC section point | |
6253 | at the file offset, not the memory address, for the | |
6254 | convenience of the post linker. */ | |
6255 | dyn.d_un.d_ptr = s->filepos; | |
252b5132 RH |
6256 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
6257 | break; | |
6258 | ||
229fcec5 MM |
6259 | get_vma_if_bpabi: |
6260 | if (htab->symbian_p) | |
6261 | goto get_vma; | |
6262 | break; | |
6263 | ||
252b5132 RH |
6264 | case DT_PLTRELSZ: |
6265 | s = bfd_get_section_by_name (output_bfd, ".rel.plt"); | |
6266 | BFD_ASSERT (s != NULL); | |
eea6121a | 6267 | dyn.d_un.d_val = s->size; |
252b5132 RH |
6268 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
6269 | break; | |
229fcec5 | 6270 | |
252b5132 | 6271 | case DT_RELSZ: |
229fcec5 MM |
6272 | if (!htab->symbian_p) |
6273 | { | |
6274 | /* My reading of the SVR4 ABI indicates that the | |
6275 | procedure linkage table relocs (DT_JMPREL) should be | |
6276 | included in the overall relocs (DT_REL). This is | |
6277 | what Solaris does. However, UnixWare can not handle | |
6278 | that case. Therefore, we override the DT_RELSZ entry | |
6279 | here to make it not include the JMPREL relocs. Since | |
6280 | the linker script arranges for .rel.plt to follow all | |
6281 | other relocation sections, we don't have to worry | |
6282 | about changing the DT_REL entry. */ | |
6283 | s = bfd_get_section_by_name (output_bfd, ".rel.plt"); | |
6284 | if (s != NULL) | |
6285 | dyn.d_un.d_val -= s->size; | |
6286 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); | |
6287 | break; | |
6288 | } | |
6289 | /* Fall through */ | |
6290 | ||
6291 | case DT_REL: | |
6292 | case DT_RELA: | |
6293 | case DT_RELASZ: | |
6294 | /* In the BPABI, the DT_REL tag must point at the file | |
6295 | offset, not the VMA, of the first relocation | |
6296 | section. So, we use code similar to that in | |
6297 | elflink.c, but do not check for SHF_ALLOC on the | |
6298 | relcoation section, since relocations sections are | |
6299 | never allocated under the BPABI. The comments above | |
6300 | about Unixware notwithstanding, we include all of the | |
6301 | relocations here. */ | |
6302 | if (htab->symbian_p) | |
6303 | { | |
6304 | unsigned int i; | |
6305 | type = ((dyn.d_tag == DT_REL || dyn.d_tag == DT_RELSZ) | |
6306 | ? SHT_REL : SHT_RELA); | |
6307 | dyn.d_un.d_val = 0; | |
6308 | for (i = 1; i < elf_numsections (output_bfd); i++) | |
6309 | { | |
6310 | Elf_Internal_Shdr *hdr | |
6311 | = elf_elfsections (output_bfd)[i]; | |
6312 | if (hdr->sh_type == type) | |
6313 | { | |
6314 | if (dyn.d_tag == DT_RELSZ | |
6315 | || dyn.d_tag == DT_RELASZ) | |
6316 | dyn.d_un.d_val += hdr->sh_size; | |
de52dba4 AM |
6317 | else if ((ufile_ptr) hdr->sh_offset |
6318 | <= dyn.d_un.d_val - 1) | |
229fcec5 MM |
6319 | dyn.d_un.d_val = hdr->sh_offset; |
6320 | } | |
6321 | } | |
6322 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); | |
6323 | } | |
252b5132 | 6324 | break; |
88f7bcd5 NC |
6325 | |
6326 | /* Set the bottom bit of DT_INIT/FINI if the | |
6327 | corresponding function is Thumb. */ | |
6328 | case DT_INIT: | |
6329 | name = info->init_function; | |
6330 | goto get_sym; | |
6331 | case DT_FINI: | |
6332 | name = info->fini_function; | |
6333 | get_sym: | |
6334 | /* If it wasn't set by elf_bfd_final_link | |
4cc11e76 | 6335 | then there is nothing to adjust. */ |
88f7bcd5 NC |
6336 | if (dyn.d_un.d_val != 0) |
6337 | { | |
6338 | struct elf_link_hash_entry * eh; | |
6339 | ||
6340 | eh = elf_link_hash_lookup (elf_hash_table (info), name, | |
b34976b6 | 6341 | FALSE, FALSE, TRUE); |
88f7bcd5 NC |
6342 | if (eh != (struct elf_link_hash_entry *) NULL |
6343 | && ELF_ST_TYPE (eh->type) == STT_ARM_TFUNC) | |
6344 | { | |
6345 | dyn.d_un.d_val |= 1; | |
b34976b6 | 6346 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
88f7bcd5 NC |
6347 | } |
6348 | } | |
6349 | break; | |
252b5132 RH |
6350 | } |
6351 | } | |
6352 | ||
24a1ba0f | 6353 | /* Fill in the first entry in the procedure linkage table. */ |
e5a52504 | 6354 | if (splt->size > 0 && elf32_arm_hash_table (info)->plt_header_size) |
f7a74f8c | 6355 | { |
5e681ec4 PB |
6356 | bfd_vma got_displacement; |
6357 | ||
6358 | /* Calculate the displacement between the PLT slot and &GOT[0]. */ | |
6359 | got_displacement = (sgot->output_section->vma | |
6360 | + sgot->output_offset | |
6361 | - splt->output_section->vma | |
6362 | - splt->output_offset | |
6363 | - 16); | |
6364 | ||
f7a74f8c NC |
6365 | bfd_put_32 (output_bfd, elf32_arm_plt0_entry[0], splt->contents + 0); |
6366 | bfd_put_32 (output_bfd, elf32_arm_plt0_entry[1], splt->contents + 4); | |
6367 | bfd_put_32 (output_bfd, elf32_arm_plt0_entry[2], splt->contents + 8); | |
6368 | bfd_put_32 (output_bfd, elf32_arm_plt0_entry[3], splt->contents + 12); | |
5e681ec4 PB |
6369 | #ifdef FOUR_WORD_PLT |
6370 | /* The displacement value goes in the otherwise-unused last word of | |
6371 | the second entry. */ | |
6372 | bfd_put_32 (output_bfd, got_displacement, splt->contents + 28); | |
6373 | #else | |
6374 | bfd_put_32 (output_bfd, got_displacement, splt->contents + 16); | |
6375 | #endif | |
f7a74f8c | 6376 | } |
252b5132 RH |
6377 | |
6378 | /* UnixWare sets the entsize of .plt to 4, although that doesn't | |
6379 | really seem like the right value. */ | |
6380 | elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4; | |
6381 | } | |
6382 | ||
6383 | /* Fill in the first three entries in the global offset table. */ | |
229fcec5 | 6384 | if (sgot) |
252b5132 | 6385 | { |
229fcec5 MM |
6386 | if (sgot->size > 0) |
6387 | { | |
6388 | if (sdyn == NULL) | |
6389 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents); | |
6390 | else | |
6391 | bfd_put_32 (output_bfd, | |
6392 | sdyn->output_section->vma + sdyn->output_offset, | |
6393 | sgot->contents); | |
6394 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4); | |
6395 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8); | |
6396 | } | |
252b5132 | 6397 | |
229fcec5 MM |
6398 | elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4; |
6399 | } | |
252b5132 | 6400 | |
b34976b6 | 6401 | return TRUE; |
252b5132 RH |
6402 | } |
6403 | ||
ba96a88f | 6404 | static void |
57e8b36a | 6405 | elf32_arm_post_process_headers (bfd * abfd, struct bfd_link_info * link_info ATTRIBUTE_UNUSED) |
ba96a88f | 6406 | { |
9b485d32 | 6407 | Elf_Internal_Ehdr * i_ehdrp; /* ELF file header, internal form. */ |
e489d0ae | 6408 | struct elf32_arm_link_hash_table *globals; |
ba96a88f NC |
6409 | |
6410 | i_ehdrp = elf_elfheader (abfd); | |
6411 | ||
94a3258f PB |
6412 | if (EF_ARM_EABI_VERSION (i_ehdrp->e_flags) == EF_ARM_EABI_UNKNOWN) |
6413 | i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_ARM; | |
6414 | else | |
6415 | i_ehdrp->e_ident[EI_OSABI] = 0; | |
ba96a88f | 6416 | i_ehdrp->e_ident[EI_ABIVERSION] = ARM_ELF_ABI_VERSION; |
e489d0ae | 6417 | |
93204d3a PB |
6418 | if (link_info) |
6419 | { | |
6420 | globals = elf32_arm_hash_table (link_info); | |
6421 | if (globals->byteswap_code) | |
6422 | i_ehdrp->e_flags |= EF_ARM_BE8; | |
6423 | } | |
ba96a88f NC |
6424 | } |
6425 | ||
99e4ae17 | 6426 | static enum elf_reloc_type_class |
57e8b36a | 6427 | elf32_arm_reloc_type_class (const Elf_Internal_Rela *rela) |
99e4ae17 | 6428 | { |
f51e552e | 6429 | switch ((int) ELF32_R_TYPE (rela->r_info)) |
99e4ae17 AJ |
6430 | { |
6431 | case R_ARM_RELATIVE: | |
6432 | return reloc_class_relative; | |
6433 | case R_ARM_JUMP_SLOT: | |
6434 | return reloc_class_plt; | |
6435 | case R_ARM_COPY: | |
6436 | return reloc_class_copy; | |
6437 | default: | |
6438 | return reloc_class_normal; | |
6439 | } | |
6440 | } | |
6441 | ||
e16bb312 NC |
6442 | /* Set the right machine number for an Arm ELF file. */ |
6443 | ||
6444 | static bfd_boolean | |
57e8b36a | 6445 | elf32_arm_section_flags (flagword *flags, const Elf_Internal_Shdr *hdr) |
e16bb312 NC |
6446 | { |
6447 | if (hdr->sh_type == SHT_NOTE) | |
6448 | *flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_SAME_CONTENTS; | |
6449 | ||
6450 | return TRUE; | |
6451 | } | |
6452 | ||
e489d0ae | 6453 | static void |
57e8b36a | 6454 | elf32_arm_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED) |
e16bb312 | 6455 | { |
5a6c6817 | 6456 | bfd_arm_update_notes (abfd, ARM_NOTE_SECTION); |
e16bb312 NC |
6457 | } |
6458 | ||
40a18ebd NC |
6459 | /* Return TRUE if this is an unwinding table entry. */ |
6460 | ||
6461 | static bfd_boolean | |
6462 | is_arm_elf_unwind_section_name (bfd * abfd ATTRIBUTE_UNUSED, const char * name) | |
6463 | { | |
6464 | size_t len1, len2; | |
6465 | ||
6466 | len1 = sizeof (ELF_STRING_ARM_unwind) - 1; | |
6467 | len2 = sizeof (ELF_STRING_ARM_unwind_once) - 1; | |
6468 | return (strncmp (name, ELF_STRING_ARM_unwind, len1) == 0 | |
6469 | || strncmp (name, ELF_STRING_ARM_unwind_once, len2) == 0); | |
6470 | } | |
6471 | ||
6472 | ||
6473 | /* Set the type and flags for an ARM section. We do this by | |
6474 | the section name, which is a hack, but ought to work. */ | |
6475 | ||
6476 | static bfd_boolean | |
6477 | elf32_arm_fake_sections (bfd * abfd, Elf_Internal_Shdr * hdr, asection * sec) | |
6478 | { | |
6479 | const char * name; | |
6480 | ||
6481 | name = bfd_get_section_name (abfd, sec); | |
6482 | ||
6483 | if (is_arm_elf_unwind_section_name (abfd, name)) | |
6484 | { | |
6485 | hdr->sh_type = SHT_ARM_EXIDX; | |
6486 | hdr->sh_flags |= SHF_LINK_ORDER; | |
6487 | } | |
6488 | return TRUE; | |
6489 | } | |
6490 | ||
6dc132d9 L |
6491 | /* Handle an ARM specific section when reading an object file. This is |
6492 | called when bfd_section_from_shdr finds a section with an unknown | |
6493 | type. */ | |
40a18ebd NC |
6494 | |
6495 | static bfd_boolean | |
6496 | elf32_arm_section_from_shdr (bfd *abfd, | |
6497 | Elf_Internal_Shdr * hdr, | |
6dc132d9 L |
6498 | const char *name, |
6499 | int shindex) | |
40a18ebd NC |
6500 | { |
6501 | /* There ought to be a place to keep ELF backend specific flags, but | |
6502 | at the moment there isn't one. We just keep track of the | |
6503 | sections by their name, instead. Fortunately, the ABI gives | |
6504 | names for all the ARM specific sections, so we will probably get | |
6505 | away with this. */ | |
6506 | switch (hdr->sh_type) | |
6507 | { | |
6508 | case SHT_ARM_EXIDX: | |
6509 | break; | |
6510 | ||
6511 | default: | |
6512 | return FALSE; | |
6513 | } | |
6514 | ||
6dc132d9 | 6515 | if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex)) |
40a18ebd NC |
6516 | return FALSE; |
6517 | ||
6518 | return TRUE; | |
6519 | } | |
e489d0ae PB |
6520 | |
6521 | /* Called for each symbol. Builds a section map based on mapping symbols. | |
6522 | Does not alter any of the symbols. */ | |
6523 | ||
6524 | static bfd_boolean | |
6525 | elf32_arm_output_symbol_hook (struct bfd_link_info *info, | |
6526 | const char *name, | |
6527 | Elf_Internal_Sym *elfsym, | |
6528 | asection *input_sec, | |
6529 | struct elf_link_hash_entry *h ATTRIBUTE_UNUSED) | |
6530 | { | |
6531 | int mapcount; | |
6532 | elf32_arm_section_map *map; | |
6533 | struct elf32_arm_link_hash_table *globals; | |
6534 | ||
6535 | /* Only do this on final link. */ | |
6536 | if (info->relocatable) | |
6537 | return TRUE; | |
6538 | ||
6539 | /* Only build a map if we need to byteswap code. */ | |
6540 | globals = elf32_arm_hash_table (info); | |
6541 | if (!globals->byteswap_code) | |
6542 | return TRUE; | |
6543 | ||
6544 | /* We only want mapping symbols. */ | |
05ea83ed | 6545 | if (! bfd_is_arm_mapping_symbol_name (name)) |
e489d0ae PB |
6546 | return TRUE; |
6547 | ||
6548 | mapcount = ++(elf32_arm_section_data (input_sec)->mapcount); | |
6549 | map = elf32_arm_section_data (input_sec)->map; | |
6550 | /* TODO: This may be inefficient, but we probably don't usually have many | |
6551 | mapping symbols per section. */ | |
6552 | map = bfd_realloc (map, mapcount * sizeof (elf32_arm_section_map)); | |
6553 | elf32_arm_section_data (input_sec)->map = map; | |
57e8b36a | 6554 | |
e489d0ae PB |
6555 | map[mapcount - 1].vma = elfsym->st_value; |
6556 | map[mapcount - 1].type = name[1]; | |
6557 | return TRUE; | |
6558 | } | |
6559 | ||
6560 | ||
6561 | /* Allocate target specific section data. */ | |
6562 | ||
6563 | static bfd_boolean | |
6564 | elf32_arm_new_section_hook (bfd *abfd, asection *sec) | |
6565 | { | |
6566 | struct _arm_elf_section_data *sdata; | |
6567 | bfd_size_type amt = sizeof (*sdata); | |
6568 | ||
6569 | sdata = bfd_zalloc (abfd, amt); | |
6570 | if (sdata == NULL) | |
6571 | return FALSE; | |
6572 | sec->used_by_bfd = sdata; | |
6573 | ||
6574 | return _bfd_elf_new_section_hook (abfd, sec); | |
6575 | } | |
6576 | ||
6577 | ||
6578 | /* Used to order a list of mapping symbols by address. */ | |
6579 | ||
6580 | static int | |
6581 | elf32_arm_compare_mapping (const void * a, const void * b) | |
6582 | { | |
6583 | return ((const elf32_arm_section_map *) a)->vma | |
6584 | > ((const elf32_arm_section_map *) b)->vma; | |
6585 | } | |
6586 | ||
6587 | ||
6588 | /* Do code byteswapping. Return FALSE afterwards so that the section is | |
6589 | written out as normal. */ | |
6590 | ||
6591 | static bfd_boolean | |
6592 | elf32_arm_write_section (bfd *output_bfd ATTRIBUTE_UNUSED, asection *sec, | |
6593 | bfd_byte *contents) | |
6594 | { | |
6595 | int mapcount; | |
6596 | elf32_arm_section_map *map; | |
6597 | bfd_vma ptr; | |
6598 | bfd_vma end; | |
6599 | bfd_vma offset; | |
6600 | bfd_byte tmp; | |
6601 | int i; | |
57e8b36a | 6602 | |
e489d0ae PB |
6603 | mapcount = elf32_arm_section_data (sec)->mapcount; |
6604 | map = elf32_arm_section_data (sec)->map; | |
6605 | ||
6606 | if (mapcount == 0) | |
6607 | return FALSE; | |
6608 | ||
6609 | qsort (map, mapcount, sizeof (elf32_arm_section_map), | |
6610 | elf32_arm_compare_mapping); | |
6611 | ||
6612 | offset = sec->output_section->vma + sec->output_offset; | |
6613 | ptr = map[0].vma - offset; | |
6614 | for (i = 0; i < mapcount; i++) | |
6615 | { | |
6616 | if (i == mapcount - 1) | |
eea6121a | 6617 | end = sec->size; |
e489d0ae PB |
6618 | else |
6619 | end = map[i + 1].vma - offset; | |
57e8b36a | 6620 | |
e489d0ae PB |
6621 | switch (map[i].type) |
6622 | { | |
6623 | case 'a': | |
6624 | /* Byte swap code words. */ | |
6625 | while (ptr + 3 < end) | |
6626 | { | |
6627 | tmp = contents[ptr]; | |
6628 | contents[ptr] = contents[ptr + 3]; | |
6629 | contents[ptr + 3] = tmp; | |
6630 | tmp = contents[ptr + 1]; | |
6631 | contents[ptr + 1] = contents[ptr + 2]; | |
6632 | contents[ptr + 2] = tmp; | |
6633 | ptr += 4; | |
6634 | } | |
6635 | break; | |
6636 | ||
6637 | case 't': | |
6638 | /* Byte swap code halfwords. */ | |
6639 | while (ptr + 1 < end) | |
6640 | { | |
6641 | tmp = contents[ptr]; | |
6642 | contents[ptr] = contents[ptr + 1]; | |
6643 | contents[ptr + 1] = tmp; | |
6644 | ptr += 2; | |
6645 | } | |
6646 | break; | |
6647 | ||
6648 | case 'd': | |
6649 | /* Leave data alone. */ | |
6650 | break; | |
6651 | } | |
6652 | ptr = end; | |
6653 | } | |
93204d3a | 6654 | free (map); |
e489d0ae PB |
6655 | return FALSE; |
6656 | } | |
6657 | ||
b7693d02 DJ |
6658 | /* Display STT_ARM_TFUNC symbols as functions. */ |
6659 | ||
6660 | static void | |
6661 | elf32_arm_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED, | |
6662 | asymbol *asym) | |
6663 | { | |
6664 | elf_symbol_type *elfsym = (elf_symbol_type *) asym; | |
6665 | ||
6666 | if (ELF_ST_TYPE (elfsym->internal_elf_sym.st_info) == STT_ARM_TFUNC) | |
6667 | elfsym->symbol.flags |= BSF_FUNCTION; | |
6668 | } | |
6669 | ||
0beaef2b PB |
6670 | |
6671 | /* Mangle thumb function symbols as we read them in. */ | |
6672 | ||
6673 | static void | |
6674 | elf32_arm_swap_symbol_in (bfd * abfd, | |
6675 | const void *psrc, | |
6676 | const void *pshn, | |
6677 | Elf_Internal_Sym *dst) | |
6678 | { | |
6679 | bfd_elf32_swap_symbol_in (abfd, psrc, pshn, dst); | |
6680 | ||
6681 | /* New EABI objects mark thumb function symbols by setting the low bit of | |
6682 | the address. Turn these into STT_ARM_TFUNC. */ | |
6683 | if (ELF_ST_TYPE (dst->st_info) == STT_FUNC | |
6684 | && (dst->st_value & 1)) | |
6685 | { | |
6686 | dst->st_info = ELF_ST_INFO (ELF_ST_BIND (dst->st_info), STT_ARM_TFUNC); | |
6687 | dst->st_value &= ~(bfd_vma) 1; | |
6688 | } | |
6689 | } | |
6690 | ||
6691 | ||
6692 | /* Mangle thumb function symbols as we write them out. */ | |
6693 | ||
6694 | static void | |
6695 | elf32_arm_swap_symbol_out (bfd *abfd, | |
6696 | const Elf_Internal_Sym *src, | |
6697 | void *cdst, | |
6698 | void *shndx) | |
6699 | { | |
6700 | Elf_Internal_Sym newsym; | |
6701 | ||
6702 | /* We convert STT_ARM_TFUNC symbols into STT_FUNC with the low bit | |
6703 | of the address set, as per the new EABI. We do this unconditionally | |
6704 | because objcopy does not set the elf header flags until after | |
6705 | it writes out the symbol table. */ | |
6706 | if (ELF_ST_TYPE (src->st_info) == STT_ARM_TFUNC) | |
6707 | { | |
6708 | newsym = *src; | |
6709 | newsym.st_info = ELF_ST_INFO (ELF_ST_BIND (src->st_info), STT_FUNC); | |
6710 | newsym.st_value |= 1; | |
6711 | ||
6712 | src = &newsym; | |
6713 | } | |
6714 | bfd_elf32_swap_symbol_out (abfd, src, cdst, shndx); | |
6715 | } | |
6716 | ||
b294bdf8 MM |
6717 | /* Add the PT_ARM_EXIDX program header. */ |
6718 | ||
6719 | static bfd_boolean | |
6720 | elf32_arm_modify_segment_map (bfd *abfd, | |
6721 | struct bfd_link_info *info ATTRIBUTE_UNUSED) | |
6722 | { | |
6723 | struct elf_segment_map *m; | |
6724 | asection *sec; | |
6725 | ||
6726 | sec = bfd_get_section_by_name (abfd, ".ARM.exidx"); | |
6727 | if (sec != NULL && (sec->flags & SEC_LOAD) != 0) | |
6728 | { | |
6729 | /* If there is already a PT_ARM_EXIDX header, then we do not | |
6730 | want to add another one. This situation arises when running | |
6731 | "strip"; the input binary already has the header. */ | |
6732 | m = elf_tdata (abfd)->segment_map; | |
6733 | while (m && m->p_type != PT_ARM_EXIDX) | |
6734 | m = m->next; | |
6735 | if (!m) | |
6736 | { | |
6737 | m = bfd_zalloc (abfd, sizeof (struct elf_segment_map)); | |
6738 | if (m == NULL) | |
6739 | return FALSE; | |
6740 | m->p_type = PT_ARM_EXIDX; | |
6741 | m->count = 1; | |
6742 | m->sections[0] = sec; | |
6743 | ||
6744 | m->next = elf_tdata (abfd)->segment_map; | |
6745 | elf_tdata (abfd)->segment_map = m; | |
6746 | } | |
6747 | } | |
6748 | ||
6749 | return TRUE; | |
6750 | } | |
6751 | ||
6752 | /* We may add a PT_ARM_EXIDX program header. */ | |
6753 | ||
6754 | static int | |
6755 | elf32_arm_additional_program_headers (bfd *abfd) | |
6756 | { | |
6757 | asection *sec; | |
6758 | ||
6759 | sec = bfd_get_section_by_name (abfd, ".ARM.exidx"); | |
6760 | if (sec != NULL && (sec->flags & SEC_LOAD) != 0) | |
6761 | return 1; | |
6762 | else | |
6763 | return 0; | |
6764 | } | |
6765 | ||
0beaef2b PB |
6766 | /* We use this to override swap_symbol_in and swap_symbol_out. */ |
6767 | const struct elf_size_info elf32_arm_size_info = { | |
6768 | sizeof (Elf32_External_Ehdr), | |
6769 | sizeof (Elf32_External_Phdr), | |
6770 | sizeof (Elf32_External_Shdr), | |
6771 | sizeof (Elf32_External_Rel), | |
6772 | sizeof (Elf32_External_Rela), | |
6773 | sizeof (Elf32_External_Sym), | |
6774 | sizeof (Elf32_External_Dyn), | |
6775 | sizeof (Elf_External_Note), | |
6776 | 4, | |
6777 | 1, | |
6778 | 32, 2, | |
6779 | ELFCLASS32, EV_CURRENT, | |
6780 | bfd_elf32_write_out_phdrs, | |
6781 | bfd_elf32_write_shdrs_and_ehdr, | |
6782 | bfd_elf32_write_relocs, | |
6783 | elf32_arm_swap_symbol_in, | |
6784 | elf32_arm_swap_symbol_out, | |
6785 | bfd_elf32_slurp_reloc_table, | |
6786 | bfd_elf32_slurp_symbol_table, | |
6787 | bfd_elf32_swap_dyn_in, | |
6788 | bfd_elf32_swap_dyn_out, | |
6789 | bfd_elf32_swap_reloc_in, | |
6790 | bfd_elf32_swap_reloc_out, | |
6791 | bfd_elf32_swap_reloca_in, | |
6792 | bfd_elf32_swap_reloca_out | |
6793 | }; | |
6794 | ||
252b5132 RH |
6795 | #define ELF_ARCH bfd_arch_arm |
6796 | #define ELF_MACHINE_CODE EM_ARM | |
d0facd1b NC |
6797 | #ifdef __QNXTARGET__ |
6798 | #define ELF_MAXPAGESIZE 0x1000 | |
6799 | #else | |
f21f3fe0 | 6800 | #define ELF_MAXPAGESIZE 0x8000 |
d0facd1b | 6801 | #endif |
b1342370 | 6802 | #define ELF_MINPAGESIZE 0x1000 |
252b5132 | 6803 | |
ba93b8ac DJ |
6804 | #define bfd_elf32_mkobject elf32_arm_mkobject |
6805 | ||
99e4ae17 AJ |
6806 | #define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data |
6807 | #define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data | |
252b5132 RH |
6808 | #define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags |
6809 | #define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data | |
6810 | #define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create | |
dc810e39 | 6811 | #define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup |
252b5132 | 6812 | #define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line |
e489d0ae | 6813 | #define bfd_elf32_new_section_hook elf32_arm_new_section_hook |
3c9458e9 | 6814 | #define bfd_elf32_bfd_is_target_special_symbol elf32_arm_is_target_special_symbol |
252b5132 RH |
6815 | |
6816 | #define elf_backend_get_symbol_type elf32_arm_get_symbol_type | |
6817 | #define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook | |
6818 | #define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook | |
6819 | #define elf_backend_check_relocs elf32_arm_check_relocs | |
dc810e39 | 6820 | #define elf_backend_relocate_section elf32_arm_relocate_section |
e489d0ae | 6821 | #define elf_backend_write_section elf32_arm_write_section |
252b5132 | 6822 | #define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol |
5e681ec4 | 6823 | #define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections |
252b5132 RH |
6824 | #define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol |
6825 | #define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections | |
e489d0ae | 6826 | #define elf_backend_link_output_symbol_hook elf32_arm_output_symbol_hook |
252b5132 | 6827 | #define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections |
ba96a88f | 6828 | #define elf_backend_post_process_headers elf32_arm_post_process_headers |
99e4ae17 | 6829 | #define elf_backend_reloc_type_class elf32_arm_reloc_type_class |
c178919b | 6830 | #define elf_backend_object_p elf32_arm_object_p |
e16bb312 | 6831 | #define elf_backend_section_flags elf32_arm_section_flags |
40a18ebd NC |
6832 | #define elf_backend_fake_sections elf32_arm_fake_sections |
6833 | #define elf_backend_section_from_shdr elf32_arm_section_from_shdr | |
e16bb312 | 6834 | #define elf_backend_final_write_processing elf32_arm_final_write_processing |
5e681ec4 | 6835 | #define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol |
b7693d02 | 6836 | #define elf_backend_symbol_processing elf32_arm_symbol_processing |
0beaef2b | 6837 | #define elf_backend_size_info elf32_arm_size_info |
b294bdf8 MM |
6838 | #define elf_backend_modify_segment_map elf32_arm_modify_segment_map |
6839 | #define elf_backend_additional_program_headers \ | |
6840 | elf32_arm_additional_program_headers | |
252b5132 | 6841 | |
5e681ec4 | 6842 | #define elf_backend_can_refcount 1 |
252b5132 RH |
6843 | #define elf_backend_can_gc_sections 1 |
6844 | #define elf_backend_plt_readonly 1 | |
6845 | #define elf_backend_want_got_plt 1 | |
6846 | #define elf_backend_want_plt_sym 0 | |
4e7fd91e PB |
6847 | #define elf_backend_may_use_rel_p 1 |
6848 | #define elf_backend_may_use_rela_p 0 | |
6849 | #define elf_backend_default_use_rela_p 0 | |
6850 | #define elf_backend_rela_normal 0 | |
252b5132 | 6851 | |
04f7c78d | 6852 | #define elf_backend_got_header_size 12 |
04f7c78d | 6853 | |
252b5132 | 6854 | #include "elf32-target.h" |
7f266840 | 6855 | |
4e7fd91e PB |
6856 | /* VxWorks Targets */ |
6857 | ||
6858 | #undef TARGET_LITTLE_SYM | |
6859 | #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vxworks_vec | |
6860 | #undef TARGET_LITTLE_NAME | |
6861 | #define TARGET_LITTLE_NAME "elf32-littlearm-vxworks" | |
6862 | #undef TARGET_BIG_SYM | |
6863 | #define TARGET_BIG_SYM bfd_elf32_bigarm_vxworks_vec | |
6864 | #undef TARGET_BIG_NAME | |
6865 | #define TARGET_BIG_NAME "elf32-bigarm-vxworks" | |
6866 | ||
6867 | /* Like elf32_arm_link_hash_table_create -- but overrides | |
6868 | appropriately for VxWorks. */ | |
6869 | static struct bfd_link_hash_table * | |
6870 | elf32_arm_vxworks_link_hash_table_create (bfd *abfd) | |
6871 | { | |
6872 | struct bfd_link_hash_table *ret; | |
6873 | ||
6874 | ret = elf32_arm_link_hash_table_create (abfd); | |
6875 | if (ret) | |
6876 | { | |
6877 | struct elf32_arm_link_hash_table *htab | |
6878 | = (struct elf32_arm_link_hash_table *)ret; | |
6879 | htab->use_rel = 0; | |
6880 | } | |
6881 | return ret; | |
6882 | } | |
6883 | ||
6884 | #undef elf32_bed | |
6885 | #define elf32_bed elf32_arm_vxworks_bed | |
6886 | ||
6887 | #undef bfd_elf32_bfd_link_hash_table_create | |
6888 | #define bfd_elf32_bfd_link_hash_table_create \ | |
6889 | elf32_arm_vxworks_link_hash_table_create | |
6890 | ||
6891 | #undef elf_backend_may_use_rel_p | |
6892 | #define elf_backend_may_use_rel_p 0 | |
6893 | #undef elf_backend_may_use_rela_p | |
6894 | #define elf_backend_may_use_rela_p 1 | |
6895 | #undef elf_backend_default_use_rela_p | |
6896 | #define elf_backend_default_use_rela_p 1 | |
6897 | #undef elf_backend_rela_normal | |
6898 | #define elf_backend_rela_normal 1 | |
6899 | ||
6900 | #include "elf32-target.h" | |
6901 | ||
6902 | ||
7f266840 DJ |
6903 | /* Symbian OS Targets */ |
6904 | ||
6905 | #undef TARGET_LITTLE_SYM | |
6906 | #define TARGET_LITTLE_SYM bfd_elf32_littlearm_symbian_vec | |
6907 | #undef TARGET_LITTLE_NAME | |
6908 | #define TARGET_LITTLE_NAME "elf32-littlearm-symbian" | |
6909 | #undef TARGET_BIG_SYM | |
6910 | #define TARGET_BIG_SYM bfd_elf32_bigarm_symbian_vec | |
6911 | #undef TARGET_BIG_NAME | |
6912 | #define TARGET_BIG_NAME "elf32-bigarm-symbian" | |
6913 | ||
6914 | /* Like elf32_arm_link_hash_table_create -- but overrides | |
6915 | appropriately for Symbian OS. */ | |
6916 | static struct bfd_link_hash_table * | |
6917 | elf32_arm_symbian_link_hash_table_create (bfd *abfd) | |
6918 | { | |
6919 | struct bfd_link_hash_table *ret; | |
6920 | ||
6921 | ret = elf32_arm_link_hash_table_create (abfd); | |
6922 | if (ret) | |
6923 | { | |
6924 | struct elf32_arm_link_hash_table *htab | |
6925 | = (struct elf32_arm_link_hash_table *)ret; | |
6926 | /* There is no PLT header for Symbian OS. */ | |
6927 | htab->plt_header_size = 0; | |
6928 | /* The PLT entries are each three instructions. */ | |
6929 | htab->plt_entry_size = 4 * NUM_ELEM (elf32_arm_symbian_plt_entry); | |
6930 | htab->symbian_p = 1; | |
33bfe774 JB |
6931 | /* Symbian uses armv5t or above, so use_blx is always true. */ |
6932 | htab->use_blx = 1; | |
67687978 | 6933 | htab->root.is_relocatable_executable = 1; |
7f266840 DJ |
6934 | } |
6935 | return ret; | |
6936 | } | |
6937 | ||
7f4d3958 L |
6938 | static struct bfd_elf_special_section const |
6939 | symbian_special_sections_d[]= | |
7f266840 | 6940 | { |
5cd3778d MM |
6941 | /* In a BPABI executable, the dynamic linking sections do not go in |
6942 | the loadable read-only segment. The post-linker may wish to | |
6943 | refer to these sections, but they are not part of the final | |
6944 | program image. */ | |
7f266840 DJ |
6945 | { ".dynamic", 8, 0, SHT_DYNAMIC, 0 }, |
6946 | { ".dynstr", 7, 0, SHT_STRTAB, 0 }, | |
6947 | { ".dynsym", 7, 0, SHT_DYNSYM, 0 }, | |
7f4d3958 L |
6948 | { NULL, 0, 0, 0, 0 } |
6949 | }; | |
6950 | ||
6951 | static struct bfd_elf_special_section const | |
6952 | symbian_special_sections_g[]= | |
6953 | { | |
6954 | /* In a BPABI executable, the dynamic linking sections do not go in | |
6955 | the loadable read-only segment. The post-linker may wish to | |
6956 | refer to these sections, but they are not part of the final | |
6957 | program image. */ | |
7f266840 | 6958 | { ".got", 4, 0, SHT_PROGBITS, 0 }, |
7f4d3958 L |
6959 | { NULL, 0, 0, 0, 0 } |
6960 | }; | |
6961 | ||
6962 | static struct bfd_elf_special_section const | |
6963 | symbian_special_sections_h[]= | |
6964 | { | |
6965 | /* In a BPABI executable, the dynamic linking sections do not go in | |
6966 | the loadable read-only segment. The post-linker may wish to | |
6967 | refer to these sections, but they are not part of the final | |
6968 | program image. */ | |
7f266840 | 6969 | { ".hash", 5, 0, SHT_HASH, 0 }, |
7f4d3958 L |
6970 | { NULL, 0, 0, 0, 0 } |
6971 | }; | |
6972 | ||
6973 | static struct bfd_elf_special_section const | |
6974 | symbian_special_sections_i[]= | |
6975 | { | |
5cd3778d MM |
6976 | /* These sections do not need to be writable as the SymbianOS |
6977 | postlinker will arrange things so that no dynamic relocation is | |
6978 | required. */ | |
6979 | { ".init_array", 11, 0, SHT_INIT_ARRAY, SHF_ALLOC }, | |
7f4d3958 L |
6980 | { NULL, 0, 0, 0, 0 } |
6981 | }; | |
6982 | ||
6983 | static struct bfd_elf_special_section const | |
6984 | symbian_special_sections_f[]= | |
6985 | { | |
6986 | /* These sections do not need to be writable as the SymbianOS | |
6987 | postlinker will arrange things so that no dynamic relocation is | |
6988 | required. */ | |
5cd3778d | 6989 | { ".fini_array", 11, 0, SHT_FINI_ARRAY, SHF_ALLOC }, |
7f4d3958 L |
6990 | { NULL, 0, 0, 0, 0 } |
6991 | }; | |
6992 | ||
6993 | static struct bfd_elf_special_section const | |
6994 | symbian_special_sections_p[]= | |
6995 | { | |
6996 | /* These sections do not need to be writable as the SymbianOS | |
6997 | postlinker will arrange things so that no dynamic relocation is | |
6998 | required. */ | |
5cd3778d | 6999 | { ".preinit_array", 14, 0, SHT_PREINIT_ARRAY, SHF_ALLOC }, |
7f266840 DJ |
7000 | { NULL, 0, 0, 0, 0 } |
7001 | }; | |
7002 | ||
7f4d3958 L |
7003 | static struct bfd_elf_special_section const * |
7004 | elf32_arm_symbian_special_sections[27]= | |
7005 | { | |
7006 | NULL, /* 'a' */ | |
7007 | NULL, /* 'b' */ | |
7008 | NULL, /* 'c' */ | |
7009 | symbian_special_sections_d, /* 'd' */ | |
7010 | NULL, /* 'e' */ | |
7011 | symbian_special_sections_f, /* 'f' */ | |
7012 | symbian_special_sections_g, /* 'g' */ | |
7013 | symbian_special_sections_h, /* 'h' */ | |
7014 | symbian_special_sections_i, /* 'i' */ | |
7015 | NULL, /* 'j' */ | |
7016 | NULL, /* 'k' */ | |
7017 | NULL, /* 'l' */ | |
7018 | NULL, /* 'm' */ | |
7019 | NULL, /* 'n' */ | |
7020 | NULL, /* 'o' */ | |
7021 | symbian_special_sections_p, /* 'p' */ | |
7022 | NULL, /* 'q' */ | |
7023 | NULL, /* 'r' */ | |
7024 | NULL, /* 's' */ | |
7025 | NULL, /* 't' */ | |
7026 | NULL, /* 'u' */ | |
7027 | NULL, /* 'v' */ | |
7028 | NULL, /* 'w' */ | |
7029 | NULL, /* 'x' */ | |
7030 | NULL, /* 'y' */ | |
7031 | NULL, /* 'z' */ | |
7032 | NULL /* other */ | |
7033 | }; | |
7034 | ||
c3c76620 | 7035 | static void |
b34af79c MM |
7036 | elf32_arm_symbian_begin_write_processing (bfd *abfd, |
7037 | struct bfd_link_info *link_info | |
7038 | ATTRIBUTE_UNUSED) | |
c3c76620 MM |
7039 | { |
7040 | /* BPABI objects are never loaded directly by an OS kernel; they are | |
7041 | processed by a postlinker first, into an OS-specific format. If | |
7042 | the D_PAGED bit is set on the file, BFD will align segments on | |
7043 | page boundaries, so that an OS can directly map the file. With | |
7044 | BPABI objects, that just results in wasted space. In addition, | |
7045 | because we clear the D_PAGED bit, map_sections_to_segments will | |
7046 | recognize that the program headers should not be mapped into any | |
7047 | loadable segment. */ | |
7048 | abfd->flags &= ~D_PAGED; | |
7049 | } | |
7f266840 DJ |
7050 | |
7051 | static bfd_boolean | |
b34af79c | 7052 | elf32_arm_symbian_modify_segment_map (bfd *abfd, |
b294bdf8 | 7053 | struct bfd_link_info *info) |
7f266840 DJ |
7054 | { |
7055 | struct elf_segment_map *m; | |
7056 | asection *dynsec; | |
7057 | ||
7f266840 DJ |
7058 | /* BPABI shared libraries and executables should have a PT_DYNAMIC |
7059 | segment. However, because the .dynamic section is not marked | |
7060 | with SEC_LOAD, the generic ELF code will not create such a | |
7061 | segment. */ | |
7062 | dynsec = bfd_get_section_by_name (abfd, ".dynamic"); | |
7063 | if (dynsec) | |
7064 | { | |
7065 | m = _bfd_elf_make_dynamic_segment (abfd, dynsec); | |
7066 | m->next = elf_tdata (abfd)->segment_map; | |
7067 | elf_tdata (abfd)->segment_map = m; | |
7068 | } | |
7069 | ||
b294bdf8 MM |
7070 | /* Also call the generic arm routine. */ |
7071 | return elf32_arm_modify_segment_map (abfd, info); | |
7f266840 DJ |
7072 | } |
7073 | ||
7074 | #undef elf32_bed | |
7075 | #define elf32_bed elf32_arm_symbian_bed | |
7076 | ||
7077 | /* The dynamic sections are not allocated on SymbianOS; the postlinker | |
7078 | will process them and then discard them. */ | |
7079 | #undef ELF_DYNAMIC_SEC_FLAGS | |
7080 | #define ELF_DYNAMIC_SEC_FLAGS \ | |
7081 | (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED) | |
7082 | ||
7083 | #undef bfd_elf32_bfd_link_hash_table_create | |
7084 | #define bfd_elf32_bfd_link_hash_table_create \ | |
7085 | elf32_arm_symbian_link_hash_table_create | |
7086 | ||
7087 | #undef elf_backend_special_sections | |
7088 | #define elf_backend_special_sections elf32_arm_symbian_special_sections | |
7089 | ||
c3c76620 MM |
7090 | #undef elf_backend_begin_write_processing |
7091 | #define elf_backend_begin_write_processing \ | |
7092 | elf32_arm_symbian_begin_write_processing | |
7093 | ||
7f266840 DJ |
7094 | #undef elf_backend_modify_segment_map |
7095 | #define elf_backend_modify_segment_map elf32_arm_symbian_modify_segment_map | |
7096 | ||
7097 | /* There is no .got section for BPABI objects, and hence no header. */ | |
7098 | #undef elf_backend_got_header_size | |
7099 | #define elf_backend_got_header_size 0 | |
7100 | ||
7101 | /* Similarly, there is no .got.plt section. */ | |
7102 | #undef elf_backend_want_got_plt | |
7103 | #define elf_backend_want_got_plt 0 | |
7104 | ||
4e7fd91e PB |
7105 | #undef elf_backend_may_use_rel_p |
7106 | #define elf_backend_may_use_rel_p 1 | |
7107 | #undef elf_backend_may_use_rela_p | |
7108 | #define elf_backend_may_use_rela_p 0 | |
7109 | #undef elf_backend_default_use_rela_p | |
dc4c9c19 | 7110 | #define elf_backend_default_use_rela_p 0 |
4e7fd91e PB |
7111 | #undef elf_backend_rela_normal |
7112 | #define elf_backend_rela_normal 0 | |
7113 | ||
7f266840 | 7114 | #include "elf32-target.h" |