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