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