]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/binutils/bfd/elf32-arm.c
MFV r293125: less v481.
[FreeBSD/FreeBSD.git] / contrib / binutils / bfd / elf32-arm.c
1 /* 32-bit ELF support for ARM
2    Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
3    Free Software Foundation, Inc.
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
19    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
20
21 #include "sysdep.h"
22 #include "bfd.h"
23 #include "libiberty.h"
24 #include "libbfd.h"
25 #include "elf-bfd.h"
26 #include "elf-vxworks.h"
27 #include "elf/arm.h"
28
29 #ifndef NUM_ELEM
30 #define NUM_ELEM(a)  (sizeof (a) / (sizeof (a)[0]))
31 #endif
32
33 /* Return the relocation section associated with NAME.  HTAB is the
34    bfd's elf32_arm_link_hash_entry.  */
35 #define RELOC_SECTION(HTAB, NAME) \
36   ((HTAB)->use_rel ? ".rel" NAME : ".rela" NAME)
37
38 /* Return size of a relocation entry.  HTAB is the bfd's
39    elf32_arm_link_hash_entry.  */
40 #define RELOC_SIZE(HTAB) \
41   ((HTAB)->use_rel \
42    ? sizeof (Elf32_External_Rel) \
43    : sizeof (Elf32_External_Rela))
44
45 /* Return function to swap relocations in.  HTAB is the bfd's
46    elf32_arm_link_hash_entry.  */
47 #define SWAP_RELOC_IN(HTAB) \
48   ((HTAB)->use_rel \
49    ? bfd_elf32_swap_reloc_in \
50    : bfd_elf32_swap_reloca_in)
51
52 /* Return function to swap relocations out.  HTAB is the bfd's
53    elf32_arm_link_hash_entry.  */
54 #define SWAP_RELOC_OUT(HTAB) \
55   ((HTAB)->use_rel \
56    ? bfd_elf32_swap_reloc_out \
57    : bfd_elf32_swap_reloca_out)
58
59 #define elf_info_to_howto               0
60 #define elf_info_to_howto_rel           elf32_arm_info_to_howto
61
62 #define ARM_ELF_ABI_VERSION             0
63 #ifdef __FreeBSD__
64 #define ARM_ELF_OS_ABI_VERSION          ELFOSABI_FREEBSD
65 #else
66 #define ARM_ELF_OS_ABI_VERSION          ELFOSABI_ARM
67 #endif
68
69 static struct elf_backend_data elf32_arm_vxworks_bed;
70
71 /* Note: code such as elf32_arm_reloc_type_lookup expect to use e.g.
72    R_ARM_PC24 as an index into this, and find the R_ARM_PC24 HOWTO
73    in that slot.  */
74
75 static reloc_howto_type elf32_arm_howto_table_1[] =
76 {
77   /* No relocation */
78   HOWTO (R_ARM_NONE,            /* type */
79          0,                     /* rightshift */
80          0,                     /* size (0 = byte, 1 = short, 2 = long) */
81          0,                     /* bitsize */
82          FALSE,                 /* pc_relative */
83          0,                     /* bitpos */
84          complain_overflow_dont,/* complain_on_overflow */
85          bfd_elf_generic_reloc, /* special_function */
86          "R_ARM_NONE",          /* name */
87          FALSE,                 /* partial_inplace */
88          0,                     /* src_mask */
89          0,                     /* dst_mask */
90          FALSE),                /* pcrel_offset */
91
92   HOWTO (R_ARM_PC24,            /* type */
93          2,                     /* rightshift */
94          2,                     /* size (0 = byte, 1 = short, 2 = long) */
95          24,                    /* bitsize */
96          TRUE,                  /* pc_relative */
97          0,                     /* bitpos */
98          complain_overflow_signed,/* complain_on_overflow */
99          bfd_elf_generic_reloc, /* special_function */
100          "R_ARM_PC24",          /* name */
101          FALSE,                 /* partial_inplace */
102          0x00ffffff,            /* src_mask */
103          0x00ffffff,            /* dst_mask */
104          TRUE),                 /* pcrel_offset */
105
106   /* 32 bit absolute */
107   HOWTO (R_ARM_ABS32,           /* type */
108          0,                     /* rightshift */
109          2,                     /* size (0 = byte, 1 = short, 2 = long) */
110          32,                    /* bitsize */
111          FALSE,                 /* pc_relative */
112          0,                     /* bitpos */
113          complain_overflow_bitfield,/* complain_on_overflow */
114          bfd_elf_generic_reloc, /* special_function */
115          "R_ARM_ABS32",         /* name */
116          FALSE,                 /* partial_inplace */
117          0xffffffff,            /* src_mask */
118          0xffffffff,            /* dst_mask */
119          FALSE),                /* pcrel_offset */
120
121   /* standard 32bit pc-relative reloc */
122   HOWTO (R_ARM_REL32,           /* type */
123          0,                     /* rightshift */
124          2,                     /* size (0 = byte, 1 = short, 2 = long) */
125          32,                    /* bitsize */
126          TRUE,                  /* pc_relative */
127          0,                     /* bitpos */
128          complain_overflow_bitfield,/* complain_on_overflow */
129          bfd_elf_generic_reloc, /* special_function */
130          "R_ARM_REL32",         /* name */
131          FALSE,                 /* partial_inplace */
132          0xffffffff,            /* src_mask */
133          0xffffffff,            /* dst_mask */
134          TRUE),                 /* pcrel_offset */
135
136   /* 8 bit absolute - R_ARM_LDR_PC_G0 in AAELF */
137   HOWTO (R_ARM_LDR_PC_G0,       /* type */
138          0,                     /* rightshift */
139          0,                     /* size (0 = byte, 1 = short, 2 = long) */
140          32,                    /* bitsize */
141          TRUE,                  /* pc_relative */
142          0,                     /* bitpos */
143          complain_overflow_dont,/* complain_on_overflow */
144          bfd_elf_generic_reloc, /* special_function */
145          "R_ARM_LDR_PC_G0",     /* name */
146          FALSE,                 /* partial_inplace */
147          0xffffffff,            /* src_mask */
148          0xffffffff,            /* dst_mask */
149          TRUE),                 /* pcrel_offset */
150
151    /* 16 bit absolute */
152   HOWTO (R_ARM_ABS16,           /* type */
153          0,                     /* rightshift */
154          1,                     /* size (0 = byte, 1 = short, 2 = long) */
155          16,                    /* bitsize */
156          FALSE,                 /* pc_relative */
157          0,                     /* bitpos */
158          complain_overflow_bitfield,/* complain_on_overflow */
159          bfd_elf_generic_reloc, /* special_function */
160          "R_ARM_ABS16",         /* name */
161          FALSE,                 /* partial_inplace */
162          0x0000ffff,            /* src_mask */
163          0x0000ffff,            /* dst_mask */
164          FALSE),                /* pcrel_offset */
165
166   /* 12 bit absolute */
167   HOWTO (R_ARM_ABS12,           /* type */
168          0,                     /* rightshift */
169          2,                     /* size (0 = byte, 1 = short, 2 = long) */
170          12,                    /* bitsize */
171          FALSE,                 /* pc_relative */
172          0,                     /* bitpos */
173          complain_overflow_bitfield,/* complain_on_overflow */
174          bfd_elf_generic_reloc, /* special_function */
175          "R_ARM_ABS12",         /* name */
176          FALSE,                 /* partial_inplace */
177          0x00000fff,            /* src_mask */
178          0x00000fff,            /* dst_mask */
179          FALSE),                /* pcrel_offset */
180
181   HOWTO (R_ARM_THM_ABS5,        /* type */
182          6,                     /* rightshift */
183          1,                     /* size (0 = byte, 1 = short, 2 = long) */
184          5,                     /* bitsize */
185          FALSE,                 /* pc_relative */
186          0,                     /* bitpos */
187          complain_overflow_bitfield,/* complain_on_overflow */
188          bfd_elf_generic_reloc, /* special_function */
189          "R_ARM_THM_ABS5",      /* name */
190          FALSE,                 /* partial_inplace */
191          0x000007e0,            /* src_mask */
192          0x000007e0,            /* dst_mask */
193          FALSE),                /* pcrel_offset */
194
195   /* 8 bit absolute */
196   HOWTO (R_ARM_ABS8,            /* type */
197          0,                     /* rightshift */
198          0,                     /* size (0 = byte, 1 = short, 2 = long) */
199          8,                     /* bitsize */
200          FALSE,                 /* pc_relative */
201          0,                     /* bitpos */
202          complain_overflow_bitfield,/* complain_on_overflow */
203          bfd_elf_generic_reloc, /* special_function */
204          "R_ARM_ABS8",          /* name */
205          FALSE,                 /* partial_inplace */
206          0x000000ff,            /* src_mask */
207          0x000000ff,            /* dst_mask */
208          FALSE),                /* pcrel_offset */
209
210   HOWTO (R_ARM_SBREL32,         /* type */
211          0,                     /* rightshift */
212          2,                     /* size (0 = byte, 1 = short, 2 = long) */
213          32,                    /* bitsize */
214          FALSE,                 /* pc_relative */
215          0,                     /* bitpos */
216          complain_overflow_dont,/* complain_on_overflow */
217          bfd_elf_generic_reloc, /* special_function */
218          "R_ARM_SBREL32",       /* name */
219          FALSE,                 /* partial_inplace */
220          0xffffffff,            /* src_mask */
221          0xffffffff,            /* dst_mask */
222          FALSE),                /* pcrel_offset */
223
224   HOWTO (R_ARM_THM_CALL,        /* type */
225          1,                     /* rightshift */
226          2,                     /* size (0 = byte, 1 = short, 2 = long) */
227          25,                    /* bitsize */
228          TRUE,                  /* pc_relative */
229          0,                     /* bitpos */
230          complain_overflow_signed,/* complain_on_overflow */
231          bfd_elf_generic_reloc, /* special_function */
232          "R_ARM_THM_CALL",      /* name */
233          FALSE,                 /* partial_inplace */
234          0x07ff07ff,            /* src_mask */
235          0x07ff07ff,            /* dst_mask */
236          TRUE),                 /* pcrel_offset */
237
238   HOWTO (R_ARM_THM_PC8,         /* type */
239          1,                     /* rightshift */
240          1,                     /* size (0 = byte, 1 = short, 2 = long) */
241          8,                     /* bitsize */
242          TRUE,                  /* pc_relative */
243          0,                     /* bitpos */
244          complain_overflow_signed,/* complain_on_overflow */
245          bfd_elf_generic_reloc, /* special_function */
246          "R_ARM_THM_PC8",       /* name */
247          FALSE,                 /* partial_inplace */
248          0x000000ff,            /* src_mask */
249          0x000000ff,            /* dst_mask */
250          TRUE),                 /* pcrel_offset */
251
252   HOWTO (R_ARM_BREL_ADJ,        /* type */
253          1,                     /* rightshift */
254          1,                     /* size (0 = byte, 1 = short, 2 = long) */
255          32,                    /* bitsize */
256          FALSE,                 /* pc_relative */
257          0,                     /* bitpos */
258          complain_overflow_signed,/* complain_on_overflow */
259          bfd_elf_generic_reloc, /* special_function */
260          "R_ARM_BREL_ADJ",      /* name */
261          FALSE,                 /* partial_inplace */
262          0xffffffff,            /* src_mask */
263          0xffffffff,            /* dst_mask */
264          FALSE),                /* pcrel_offset */
265
266   HOWTO (R_ARM_SWI24,           /* type */
267          0,                     /* rightshift */
268          0,                     /* size (0 = byte, 1 = short, 2 = long) */
269          0,                     /* bitsize */
270          FALSE,                 /* pc_relative */
271          0,                     /* bitpos */
272          complain_overflow_signed,/* complain_on_overflow */
273          bfd_elf_generic_reloc, /* special_function */
274          "R_ARM_SWI24",         /* name */
275          FALSE,                 /* partial_inplace */
276          0x00000000,            /* src_mask */
277          0x00000000,            /* dst_mask */
278          FALSE),                /* pcrel_offset */
279
280   HOWTO (R_ARM_THM_SWI8,        /* type */
281          0,                     /* rightshift */
282          0,                     /* size (0 = byte, 1 = short, 2 = long) */
283          0,                     /* bitsize */
284          FALSE,                 /* pc_relative */
285          0,                     /* bitpos */
286          complain_overflow_signed,/* complain_on_overflow */
287          bfd_elf_generic_reloc, /* special_function */
288          "R_ARM_SWI8",          /* name */
289          FALSE,                 /* partial_inplace */
290          0x00000000,            /* src_mask */
291          0x00000000,            /* dst_mask */
292          FALSE),                /* pcrel_offset */
293
294   /* BLX instruction for the ARM.  */
295   HOWTO (R_ARM_XPC25,           /* type */
296          2,                     /* rightshift */
297          2,                     /* size (0 = byte, 1 = short, 2 = long) */
298          25,                    /* bitsize */
299          TRUE,                  /* pc_relative */
300          0,                     /* bitpos */
301          complain_overflow_signed,/* complain_on_overflow */
302          bfd_elf_generic_reloc, /* special_function */
303          "R_ARM_XPC25",         /* name */
304          FALSE,                 /* partial_inplace */
305          0x00ffffff,            /* src_mask */
306          0x00ffffff,            /* dst_mask */
307          TRUE),                 /* pcrel_offset */
308
309   /* BLX instruction for the Thumb.  */
310   HOWTO (R_ARM_THM_XPC22,       /* type */
311          2,                     /* rightshift */
312          2,                     /* size (0 = byte, 1 = short, 2 = long) */
313          22,                    /* bitsize */
314          TRUE,                  /* pc_relative */
315          0,                     /* bitpos */
316          complain_overflow_signed,/* complain_on_overflow */
317          bfd_elf_generic_reloc, /* special_function */
318          "R_ARM_THM_XPC22",     /* name */
319          FALSE,                 /* partial_inplace */
320          0x07ff07ff,            /* src_mask */
321          0x07ff07ff,            /* dst_mask */
322          TRUE),                 /* pcrel_offset */
323
324   /* Dynamic TLS relocations.  */
325
326   HOWTO (R_ARM_TLS_DTPMOD32,    /* type */
327          0,                     /* rightshift */
328          2,                     /* size (0 = byte, 1 = short, 2 = long) */
329          32,                    /* bitsize */
330          FALSE,                 /* pc_relative */
331          0,                     /* bitpos */
332          complain_overflow_bitfield,/* complain_on_overflow */
333          bfd_elf_generic_reloc, /* special_function */
334          "R_ARM_TLS_DTPMOD32",  /* name */
335          TRUE,                  /* partial_inplace */
336          0xffffffff,            /* src_mask */
337          0xffffffff,            /* dst_mask */
338          FALSE),                /* pcrel_offset */
339
340   HOWTO (R_ARM_TLS_DTPOFF32,    /* type */
341          0,                     /* rightshift */
342          2,                     /* size (0 = byte, 1 = short, 2 = long) */
343          32,                    /* bitsize */
344          FALSE,                 /* pc_relative */
345          0,                     /* bitpos */
346          complain_overflow_bitfield,/* complain_on_overflow */
347          bfd_elf_generic_reloc, /* special_function */
348          "R_ARM_TLS_DTPOFF32",  /* name */
349          TRUE,                  /* partial_inplace */
350          0xffffffff,            /* src_mask */
351          0xffffffff,            /* dst_mask */
352          FALSE),                /* pcrel_offset */
353
354   HOWTO (R_ARM_TLS_TPOFF32,     /* type */
355          0,                     /* rightshift */
356          2,                     /* size (0 = byte, 1 = short, 2 = long) */
357          32,                    /* bitsize */
358          FALSE,                 /* pc_relative */
359          0,                     /* bitpos */
360          complain_overflow_bitfield,/* complain_on_overflow */
361          bfd_elf_generic_reloc, /* special_function */
362          "R_ARM_TLS_TPOFF32",   /* name */
363          TRUE,                  /* partial_inplace */
364          0xffffffff,            /* src_mask */
365          0xffffffff,            /* dst_mask */
366          FALSE),                /* pcrel_offset */
367
368   /* Relocs used in ARM Linux */
369
370   HOWTO (R_ARM_COPY,            /* type */
371          0,                     /* rightshift */
372          2,                     /* size (0 = byte, 1 = short, 2 = long) */
373          32,                    /* bitsize */
374          FALSE,                 /* pc_relative */
375          0,                     /* bitpos */
376          complain_overflow_bitfield,/* complain_on_overflow */
377          bfd_elf_generic_reloc, /* special_function */
378          "R_ARM_COPY",          /* name */
379          TRUE,                  /* partial_inplace */
380          0xffffffff,            /* src_mask */
381          0xffffffff,            /* dst_mask */
382          FALSE),                /* pcrel_offset */
383
384   HOWTO (R_ARM_GLOB_DAT,        /* type */
385          0,                     /* rightshift */
386          2,                     /* size (0 = byte, 1 = short, 2 = long) */
387          32,                    /* bitsize */
388          FALSE,                 /* pc_relative */
389          0,                     /* bitpos */
390          complain_overflow_bitfield,/* complain_on_overflow */
391          bfd_elf_generic_reloc, /* special_function */
392          "R_ARM_GLOB_DAT",      /* name */
393          TRUE,                  /* partial_inplace */
394          0xffffffff,            /* src_mask */
395          0xffffffff,            /* dst_mask */
396          FALSE),                /* pcrel_offset */
397
398   HOWTO (R_ARM_JUMP_SLOT,       /* type */
399          0,                     /* rightshift */
400          2,                     /* size (0 = byte, 1 = short, 2 = long) */
401          32,                    /* bitsize */
402          FALSE,                 /* pc_relative */
403          0,                     /* bitpos */
404          complain_overflow_bitfield,/* complain_on_overflow */
405          bfd_elf_generic_reloc, /* special_function */
406          "R_ARM_JUMP_SLOT",     /* name */
407          TRUE,                  /* partial_inplace */
408          0xffffffff,            /* src_mask */
409          0xffffffff,            /* dst_mask */
410          FALSE),                /* pcrel_offset */
411
412   HOWTO (R_ARM_RELATIVE,        /* type */
413          0,                     /* rightshift */
414          2,                     /* size (0 = byte, 1 = short, 2 = long) */
415          32,                    /* bitsize */
416          FALSE,                 /* pc_relative */
417          0,                     /* bitpos */
418          complain_overflow_bitfield,/* complain_on_overflow */
419          bfd_elf_generic_reloc, /* special_function */
420          "R_ARM_RELATIVE",      /* name */
421          TRUE,                  /* partial_inplace */
422          0xffffffff,            /* src_mask */
423          0xffffffff,            /* dst_mask */
424          FALSE),                /* pcrel_offset */
425
426   HOWTO (R_ARM_GOTOFF32,        /* type */
427          0,                     /* rightshift */
428          2,                     /* size (0 = byte, 1 = short, 2 = long) */
429          32,                    /* bitsize */
430          FALSE,                 /* pc_relative */
431          0,                     /* bitpos */
432          complain_overflow_bitfield,/* complain_on_overflow */
433          bfd_elf_generic_reloc, /* special_function */
434          "R_ARM_GOTOFF32",      /* name */
435          TRUE,                  /* partial_inplace */
436          0xffffffff,            /* src_mask */
437          0xffffffff,            /* dst_mask */
438          FALSE),                /* pcrel_offset */
439
440   HOWTO (R_ARM_GOTPC,           /* type */
441          0,                     /* rightshift */
442          2,                     /* size (0 = byte, 1 = short, 2 = long) */
443          32,                    /* bitsize */
444          TRUE,                  /* pc_relative */
445          0,                     /* bitpos */
446          complain_overflow_bitfield,/* complain_on_overflow */
447          bfd_elf_generic_reloc, /* special_function */
448          "R_ARM_GOTPC",         /* name */
449          TRUE,                  /* partial_inplace */
450          0xffffffff,            /* src_mask */
451          0xffffffff,            /* dst_mask */
452          TRUE),                 /* pcrel_offset */
453
454   HOWTO (R_ARM_GOT32,           /* type */
455          0,                     /* rightshift */
456          2,                     /* size (0 = byte, 1 = short, 2 = long) */
457          32,                    /* bitsize */
458          FALSE,                 /* pc_relative */
459          0,                     /* bitpos */
460          complain_overflow_bitfield,/* complain_on_overflow */
461          bfd_elf_generic_reloc, /* special_function */
462          "R_ARM_GOT32",         /* name */
463          TRUE,                  /* partial_inplace */
464          0xffffffff,            /* src_mask */
465          0xffffffff,            /* dst_mask */
466          FALSE),                /* pcrel_offset */
467
468   HOWTO (R_ARM_PLT32,           /* type */
469          2,                     /* rightshift */
470          2,                     /* size (0 = byte, 1 = short, 2 = long) */
471          24,                    /* bitsize */
472          TRUE,                  /* pc_relative */
473          0,                     /* bitpos */
474          complain_overflow_bitfield,/* complain_on_overflow */
475          bfd_elf_generic_reloc, /* special_function */
476          "R_ARM_PLT32",         /* name */
477          FALSE,                 /* partial_inplace */
478          0x00ffffff,            /* src_mask */
479          0x00ffffff,            /* dst_mask */
480          TRUE),                 /* pcrel_offset */
481
482   HOWTO (R_ARM_CALL,            /* type */
483          2,                     /* rightshift */
484          2,                     /* size (0 = byte, 1 = short, 2 = long) */
485          24,                    /* bitsize */
486          TRUE,                  /* pc_relative */
487          0,                     /* bitpos */
488          complain_overflow_signed,/* complain_on_overflow */
489          bfd_elf_generic_reloc, /* special_function */
490          "R_ARM_CALL",          /* name */
491          FALSE,                 /* partial_inplace */
492          0x00ffffff,            /* src_mask */
493          0x00ffffff,            /* dst_mask */
494          TRUE),                 /* pcrel_offset */
495
496   HOWTO (R_ARM_JUMP24,          /* type */
497          2,                     /* rightshift */
498          2,                     /* size (0 = byte, 1 = short, 2 = long) */
499          24,                    /* bitsize */
500          TRUE,                  /* pc_relative */
501          0,                     /* bitpos */
502          complain_overflow_signed,/* complain_on_overflow */
503          bfd_elf_generic_reloc, /* special_function */
504          "R_ARM_JUMP24",        /* name */
505          FALSE,                 /* partial_inplace */
506          0x00ffffff,            /* src_mask */
507          0x00ffffff,            /* dst_mask */
508          TRUE),                 /* pcrel_offset */
509
510   HOWTO (R_ARM_THM_JUMP24,      /* type */
511          1,                     /* rightshift */
512          2,                     /* size (0 = byte, 1 = short, 2 = long) */
513          24,                    /* bitsize */
514          TRUE,                  /* pc_relative */
515          0,                     /* bitpos */
516          complain_overflow_signed,/* complain_on_overflow */
517          bfd_elf_generic_reloc, /* special_function */
518          "R_ARM_THM_JUMP24",    /* name */
519          FALSE,                 /* partial_inplace */
520          0x07ff2fff,            /* src_mask */
521          0x07ff2fff,            /* dst_mask */
522          TRUE),                 /* pcrel_offset */
523
524   HOWTO (R_ARM_BASE_ABS,        /* type */
525          0,                     /* rightshift */
526          2,                     /* size (0 = byte, 1 = short, 2 = long) */
527          32,                    /* bitsize */
528          FALSE,                 /* pc_relative */
529          0,                     /* bitpos */
530          complain_overflow_dont,/* complain_on_overflow */
531          bfd_elf_generic_reloc, /* special_function */
532          "R_ARM_BASE_ABS",      /* name */
533          FALSE,                 /* partial_inplace */
534          0xffffffff,            /* src_mask */
535          0xffffffff,            /* dst_mask */
536          FALSE),                /* pcrel_offset */
537
538   HOWTO (R_ARM_ALU_PCREL7_0,    /* type */
539          0,                     /* rightshift */
540          2,                     /* size (0 = byte, 1 = short, 2 = long) */
541          12,                    /* bitsize */
542          TRUE,                  /* pc_relative */
543          0,                     /* bitpos */
544          complain_overflow_dont,/* complain_on_overflow */
545          bfd_elf_generic_reloc, /* special_function */
546          "R_ARM_ALU_PCREL_7_0", /* name */
547          FALSE,                 /* partial_inplace */
548          0x00000fff,            /* src_mask */
549          0x00000fff,            /* dst_mask */
550          TRUE),                 /* pcrel_offset */
551
552   HOWTO (R_ARM_ALU_PCREL15_8,   /* type */
553          0,                     /* rightshift */
554          2,                     /* size (0 = byte, 1 = short, 2 = long) */
555          12,                    /* bitsize */
556          TRUE,                  /* pc_relative */
557          8,                     /* bitpos */
558          complain_overflow_dont,/* complain_on_overflow */
559          bfd_elf_generic_reloc, /* special_function */
560          "R_ARM_ALU_PCREL_15_8",/* name */
561          FALSE,                 /* partial_inplace */
562          0x00000fff,            /* src_mask */
563          0x00000fff,            /* dst_mask */
564          TRUE),                 /* pcrel_offset */
565
566   HOWTO (R_ARM_ALU_PCREL23_15,  /* type */
567          0,                     /* rightshift */
568          2,                     /* size (0 = byte, 1 = short, 2 = long) */
569          12,                    /* bitsize */
570          TRUE,                  /* pc_relative */
571          16,                    /* bitpos */
572          complain_overflow_dont,/* complain_on_overflow */
573          bfd_elf_generic_reloc, /* special_function */
574          "R_ARM_ALU_PCREL_23_15",/* name */
575          FALSE,                 /* partial_inplace */
576          0x00000fff,            /* src_mask */
577          0x00000fff,            /* dst_mask */
578          TRUE),                 /* pcrel_offset */
579
580   HOWTO (R_ARM_LDR_SBREL_11_0,  /* type */
581          0,                     /* rightshift */
582          2,                     /* size (0 = byte, 1 = short, 2 = long) */
583          12,                    /* bitsize */
584          FALSE,                 /* pc_relative */
585          0,                     /* bitpos */
586          complain_overflow_dont,/* complain_on_overflow */
587          bfd_elf_generic_reloc, /* special_function */
588          "R_ARM_LDR_SBREL_11_0",/* name */
589          FALSE,                 /* partial_inplace */
590          0x00000fff,            /* src_mask */
591          0x00000fff,            /* dst_mask */
592          FALSE),                /* pcrel_offset */
593
594   HOWTO (R_ARM_ALU_SBREL_19_12, /* type */
595          0,                     /* rightshift */
596          2,                     /* size (0 = byte, 1 = short, 2 = long) */
597          8,                     /* bitsize */
598          FALSE,                 /* pc_relative */
599          12,                    /* bitpos */
600          complain_overflow_dont,/* complain_on_overflow */
601          bfd_elf_generic_reloc, /* special_function */
602          "R_ARM_ALU_SBREL_19_12",/* name */
603          FALSE,                 /* partial_inplace */
604          0x000ff000,            /* src_mask */
605          0x000ff000,            /* dst_mask */
606          FALSE),                /* pcrel_offset */
607
608   HOWTO (R_ARM_ALU_SBREL_27_20, /* type */
609          0,                     /* rightshift */
610          2,                     /* size (0 = byte, 1 = short, 2 = long) */
611          8,                     /* bitsize */
612          FALSE,                 /* pc_relative */
613          20,                    /* bitpos */
614          complain_overflow_dont,/* complain_on_overflow */
615          bfd_elf_generic_reloc, /* special_function */
616          "R_ARM_ALU_SBREL_27_20",/* name */
617          FALSE,                 /* partial_inplace */
618          0x0ff00000,            /* src_mask */
619          0x0ff00000,            /* dst_mask */
620          FALSE),                /* pcrel_offset */
621
622   HOWTO (R_ARM_TARGET1,         /* type */
623          0,                     /* rightshift */
624          2,                     /* size (0 = byte, 1 = short, 2 = long) */
625          32,                    /* bitsize */
626          FALSE,                 /* pc_relative */
627          0,                     /* bitpos */
628          complain_overflow_dont,/* complain_on_overflow */
629          bfd_elf_generic_reloc, /* special_function */
630          "R_ARM_TARGET1",       /* name */
631          FALSE,                 /* partial_inplace */
632          0xffffffff,            /* src_mask */
633          0xffffffff,            /* dst_mask */
634          FALSE),                /* pcrel_offset */
635
636   HOWTO (R_ARM_ROSEGREL32,      /* type */
637          0,                     /* rightshift */
638          2,                     /* size (0 = byte, 1 = short, 2 = long) */
639          32,                    /* bitsize */
640          FALSE,                 /* pc_relative */
641          0,                     /* bitpos */
642          complain_overflow_dont,/* complain_on_overflow */
643          bfd_elf_generic_reloc, /* special_function */
644          "R_ARM_ROSEGREL32",    /* name */
645          FALSE,                 /* partial_inplace */
646          0xffffffff,            /* src_mask */
647          0xffffffff,            /* dst_mask */
648          FALSE),                /* pcrel_offset */
649
650   HOWTO (R_ARM_V4BX,            /* type */
651          0,                     /* rightshift */
652          2,                     /* size (0 = byte, 1 = short, 2 = long) */
653          32,                    /* bitsize */
654          FALSE,                 /* pc_relative */
655          0,                     /* bitpos */
656          complain_overflow_dont,/* complain_on_overflow */
657          bfd_elf_generic_reloc, /* special_function */
658          "R_ARM_V4BX",          /* name */
659          FALSE,                 /* partial_inplace */
660          0xffffffff,            /* src_mask */
661          0xffffffff,            /* dst_mask */
662          FALSE),                /* pcrel_offset */
663
664   HOWTO (R_ARM_TARGET2,         /* type */
665          0,                     /* rightshift */
666          2,                     /* size (0 = byte, 1 = short, 2 = long) */
667          32,                    /* bitsize */
668          FALSE,                 /* pc_relative */
669          0,                     /* bitpos */
670          complain_overflow_signed,/* complain_on_overflow */
671          bfd_elf_generic_reloc, /* special_function */
672          "R_ARM_TARGET2",       /* name */
673          FALSE,                 /* partial_inplace */
674          0xffffffff,            /* src_mask */
675          0xffffffff,            /* dst_mask */
676          TRUE),                 /* pcrel_offset */
677
678   HOWTO (R_ARM_PREL31,          /* type */
679          0,                     /* rightshift */
680          2,                     /* size (0 = byte, 1 = short, 2 = long) */
681          31,                    /* bitsize */
682          TRUE,                  /* pc_relative */
683          0,                     /* bitpos */
684          complain_overflow_signed,/* complain_on_overflow */
685          bfd_elf_generic_reloc, /* special_function */
686          "R_ARM_PREL31",        /* name */
687          FALSE,                 /* partial_inplace */
688          0x7fffffff,            /* src_mask */
689          0x7fffffff,            /* dst_mask */
690          TRUE),                 /* pcrel_offset */
691
692   HOWTO (R_ARM_MOVW_ABS_NC,     /* type */
693          0,                     /* rightshift */
694          2,                     /* size (0 = byte, 1 = short, 2 = long) */
695          16,                    /* bitsize */
696          FALSE,                 /* pc_relative */
697          0,                     /* bitpos */
698          complain_overflow_dont,/* complain_on_overflow */
699          bfd_elf_generic_reloc, /* special_function */
700          "R_ARM_MOVW_ABS_NC",   /* name */
701          FALSE,                 /* partial_inplace */
702          0x0000ffff,            /* src_mask */
703          0x0000ffff,            /* dst_mask */
704          FALSE),                /* pcrel_offset */
705
706   HOWTO (R_ARM_MOVT_ABS,        /* type */
707          0,                     /* rightshift */
708          2,                     /* size (0 = byte, 1 = short, 2 = long) */
709          16,                    /* bitsize */
710          FALSE,                 /* pc_relative */
711          0,                     /* bitpos */
712          complain_overflow_bitfield,/* complain_on_overflow */
713          bfd_elf_generic_reloc, /* special_function */
714          "R_ARM_MOVT_ABS",      /* name */
715          FALSE,                 /* partial_inplace */
716          0x0000ffff,            /* src_mask */
717          0x0000ffff,            /* dst_mask */
718          FALSE),                /* pcrel_offset */
719
720   HOWTO (R_ARM_MOVW_PREL_NC,    /* type */
721          0,                     /* rightshift */
722          2,                     /* size (0 = byte, 1 = short, 2 = long) */
723          16,                    /* bitsize */
724          TRUE,                  /* pc_relative */
725          0,                     /* bitpos */
726          complain_overflow_dont,/* complain_on_overflow */
727          bfd_elf_generic_reloc, /* special_function */
728          "R_ARM_MOVW_PREL_NC",  /* name */
729          FALSE,                 /* partial_inplace */
730          0x0000ffff,            /* src_mask */
731          0x0000ffff,            /* dst_mask */
732          TRUE),                 /* pcrel_offset */
733
734   HOWTO (R_ARM_MOVT_PREL,       /* type */
735          0,                     /* rightshift */
736          2,                     /* size (0 = byte, 1 = short, 2 = long) */
737          16,                    /* bitsize */
738          TRUE,                  /* pc_relative */
739          0,                     /* bitpos */
740          complain_overflow_bitfield,/* complain_on_overflow */
741          bfd_elf_generic_reloc, /* special_function */
742          "R_ARM_MOVT_PREL",     /* name */
743          FALSE,                 /* partial_inplace */
744          0x0000ffff,            /* src_mask */
745          0x0000ffff,            /* dst_mask */
746          TRUE),                 /* pcrel_offset */
747
748   HOWTO (R_ARM_THM_MOVW_ABS_NC, /* type */
749          0,                     /* rightshift */
750          2,                     /* size (0 = byte, 1 = short, 2 = long) */
751          16,                    /* bitsize */
752          FALSE,                 /* pc_relative */
753          0,                     /* bitpos */
754          complain_overflow_dont,/* complain_on_overflow */
755          bfd_elf_generic_reloc, /* special_function */
756          "R_ARM_THM_MOVW_ABS_NC",/* name */
757          FALSE,                 /* partial_inplace */
758          0x040f70ff,            /* src_mask */
759          0x040f70ff,            /* dst_mask */
760          FALSE),                /* pcrel_offset */
761
762   HOWTO (R_ARM_THM_MOVT_ABS,    /* type */
763          0,                     /* rightshift */
764          2,                     /* size (0 = byte, 1 = short, 2 = long) */
765          16,                    /* bitsize */
766          FALSE,                 /* pc_relative */
767          0,                     /* bitpos */
768          complain_overflow_bitfield,/* complain_on_overflow */
769          bfd_elf_generic_reloc, /* special_function */
770          "R_ARM_THM_MOVT_ABS",  /* name */
771          FALSE,                 /* partial_inplace */
772          0x040f70ff,            /* src_mask */
773          0x040f70ff,            /* dst_mask */
774          FALSE),                /* pcrel_offset */
775
776   HOWTO (R_ARM_THM_MOVW_PREL_NC,/* type */
777          0,                     /* rightshift */
778          2,                     /* size (0 = byte, 1 = short, 2 = long) */
779          16,                    /* bitsize */
780          TRUE,                  /* pc_relative */
781          0,                     /* bitpos */
782          complain_overflow_dont,/* complain_on_overflow */
783          bfd_elf_generic_reloc, /* special_function */
784          "R_ARM_THM_MOVW_PREL_NC",/* name */
785          FALSE,                 /* partial_inplace */
786          0x040f70ff,            /* src_mask */
787          0x040f70ff,            /* dst_mask */
788          TRUE),                 /* pcrel_offset */
789
790   HOWTO (R_ARM_THM_MOVT_PREL,   /* type */
791          0,                     /* rightshift */
792          2,                     /* size (0 = byte, 1 = short, 2 = long) */
793          16,                    /* bitsize */
794          TRUE,                  /* pc_relative */
795          0,                     /* bitpos */
796          complain_overflow_bitfield,/* complain_on_overflow */
797          bfd_elf_generic_reloc, /* special_function */
798          "R_ARM_THM_MOVT_PREL", /* name */
799          FALSE,                 /* partial_inplace */
800          0x040f70ff,            /* src_mask */
801          0x040f70ff,            /* dst_mask */
802          TRUE),                 /* pcrel_offset */
803
804   HOWTO (R_ARM_THM_JUMP19,      /* type */
805          1,                     /* rightshift */
806          2,                     /* size (0 = byte, 1 = short, 2 = long) */
807          19,                    /* bitsize */
808          TRUE,                  /* pc_relative */
809          0,                     /* bitpos */
810          complain_overflow_signed,/* complain_on_overflow */
811          bfd_elf_generic_reloc, /* special_function */
812          "R_ARM_THM_JUMP19",    /* name */
813          FALSE,                 /* partial_inplace */
814          0x043f2fff,            /* src_mask */
815          0x043f2fff,            /* dst_mask */
816          TRUE),                 /* pcrel_offset */
817
818   HOWTO (R_ARM_THM_JUMP6,       /* type */
819          1,                     /* rightshift */
820          1,                     /* size (0 = byte, 1 = short, 2 = long) */
821          6,                     /* bitsize */
822          TRUE,                  /* pc_relative */
823          0,                     /* bitpos */
824          complain_overflow_unsigned,/* complain_on_overflow */
825          bfd_elf_generic_reloc, /* special_function */
826          "R_ARM_THM_JUMP6",     /* name */
827          FALSE,                 /* partial_inplace */
828          0x02f8,                /* src_mask */
829          0x02f8,                /* dst_mask */
830          TRUE),                 /* pcrel_offset */
831
832   /* These are declared as 13-bit signed relocations because we can
833      address -4095 .. 4095(base) by altering ADDW to SUBW or vice
834      versa.  */
835   HOWTO (R_ARM_THM_ALU_PREL_11_0,/* type */
836          0,                     /* rightshift */
837          2,                     /* size (0 = byte, 1 = short, 2 = long) */
838          13,                    /* bitsize */
839          TRUE,                  /* pc_relative */
840          0,                     /* bitpos */
841          complain_overflow_dont,/* complain_on_overflow */
842          bfd_elf_generic_reloc, /* special_function */
843          "R_ARM_THM_ALU_PREL_11_0",/* name */
844          FALSE,                 /* partial_inplace */
845          0xffffffff,            /* src_mask */
846          0xffffffff,            /* dst_mask */
847          TRUE),                 /* pcrel_offset */
848
849   HOWTO (R_ARM_THM_PC12,        /* type */
850          0,                     /* rightshift */
851          2,                     /* size (0 = byte, 1 = short, 2 = long) */
852          13,                    /* bitsize */
853          TRUE,                  /* pc_relative */
854          0,                     /* bitpos */
855          complain_overflow_dont,/* complain_on_overflow */
856          bfd_elf_generic_reloc, /* special_function */
857          "R_ARM_THM_PC12",      /* name */
858          FALSE,                 /* partial_inplace */
859          0xffffffff,            /* src_mask */
860          0xffffffff,            /* dst_mask */
861          TRUE),                 /* pcrel_offset */
862
863   HOWTO (R_ARM_ABS32_NOI,       /* type */
864          0,                     /* rightshift */
865          2,                     /* size (0 = byte, 1 = short, 2 = long) */
866          32,                    /* bitsize */
867          FALSE,                 /* pc_relative */
868          0,                     /* bitpos */
869          complain_overflow_dont,/* complain_on_overflow */
870          bfd_elf_generic_reloc, /* special_function */
871          "R_ARM_ABS32_NOI",     /* name */
872          FALSE,                 /* partial_inplace */
873          0xffffffff,            /* src_mask */
874          0xffffffff,            /* dst_mask */
875          FALSE),                /* pcrel_offset */
876
877   HOWTO (R_ARM_REL32_NOI,       /* type */
878          0,                     /* rightshift */
879          2,                     /* size (0 = byte, 1 = short, 2 = long) */
880          32,                    /* bitsize */
881          TRUE,                  /* pc_relative */
882          0,                     /* bitpos */
883          complain_overflow_dont,/* complain_on_overflow */
884          bfd_elf_generic_reloc, /* special_function */
885          "R_ARM_REL32_NOI",     /* name */
886          FALSE,                 /* partial_inplace */
887          0xffffffff,            /* src_mask */
888          0xffffffff,            /* dst_mask */
889          FALSE),                /* pcrel_offset */
890
891   /* Group relocations.  */
892
893   HOWTO (R_ARM_ALU_PC_G0_NC,    /* type */
894          0,                     /* rightshift */
895          2,                     /* size (0 = byte, 1 = short, 2 = long) */
896          32,                    /* bitsize */
897          TRUE,                  /* pc_relative */
898          0,                     /* bitpos */
899          complain_overflow_dont,/* complain_on_overflow */
900          bfd_elf_generic_reloc, /* special_function */
901          "R_ARM_ALU_PC_G0_NC",  /* name */
902          FALSE,                 /* partial_inplace */
903          0xffffffff,            /* src_mask */
904          0xffffffff,            /* dst_mask */
905          TRUE),                 /* pcrel_offset */
906
907   HOWTO (R_ARM_ALU_PC_G0,       /* type */
908          0,                     /* rightshift */
909          2,                     /* size (0 = byte, 1 = short, 2 = long) */
910          32,                    /* bitsize */
911          TRUE,                  /* pc_relative */
912          0,                     /* bitpos */
913          complain_overflow_dont,/* complain_on_overflow */
914          bfd_elf_generic_reloc, /* special_function */
915          "R_ARM_ALU_PC_G0",     /* name */
916          FALSE,                 /* partial_inplace */
917          0xffffffff,            /* src_mask */
918          0xffffffff,            /* dst_mask */
919          TRUE),                 /* pcrel_offset */
920
921   HOWTO (R_ARM_ALU_PC_G1_NC,    /* type */
922          0,                     /* rightshift */
923          2,                     /* size (0 = byte, 1 = short, 2 = long) */
924          32,                    /* bitsize */
925          TRUE,                  /* pc_relative */
926          0,                     /* bitpos */
927          complain_overflow_dont,/* complain_on_overflow */
928          bfd_elf_generic_reloc, /* special_function */
929          "R_ARM_ALU_PC_G1_NC",  /* name */
930          FALSE,                 /* partial_inplace */
931          0xffffffff,            /* src_mask */
932          0xffffffff,            /* dst_mask */
933          TRUE),                 /* pcrel_offset */
934
935   HOWTO (R_ARM_ALU_PC_G1,       /* type */
936          0,                     /* rightshift */
937          2,                     /* size (0 = byte, 1 = short, 2 = long) */
938          32,                    /* bitsize */
939          TRUE,                  /* pc_relative */
940          0,                     /* bitpos */
941          complain_overflow_dont,/* complain_on_overflow */
942          bfd_elf_generic_reloc, /* special_function */
943          "R_ARM_ALU_PC_G1",     /* name */
944          FALSE,                 /* partial_inplace */
945          0xffffffff,            /* src_mask */
946          0xffffffff,            /* dst_mask */
947          TRUE),                 /* pcrel_offset */
948
949   HOWTO (R_ARM_ALU_PC_G2,       /* type */
950          0,                     /* rightshift */
951          2,                     /* size (0 = byte, 1 = short, 2 = long) */
952          32,                    /* bitsize */
953          TRUE,                  /* pc_relative */
954          0,                     /* bitpos */
955          complain_overflow_dont,/* complain_on_overflow */
956          bfd_elf_generic_reloc, /* special_function */
957          "R_ARM_ALU_PC_G2",     /* name */
958          FALSE,                 /* partial_inplace */
959          0xffffffff,            /* src_mask */
960          0xffffffff,            /* dst_mask */
961          TRUE),                 /* pcrel_offset */
962
963   HOWTO (R_ARM_LDR_PC_G1,       /* type */
964          0,                     /* rightshift */
965          2,                     /* size (0 = byte, 1 = short, 2 = long) */
966          32,                    /* bitsize */
967          TRUE,                  /* pc_relative */
968          0,                     /* bitpos */
969          complain_overflow_dont,/* complain_on_overflow */
970          bfd_elf_generic_reloc, /* special_function */
971          "R_ARM_LDR_PC_G1",     /* name */
972          FALSE,                 /* partial_inplace */
973          0xffffffff,            /* src_mask */
974          0xffffffff,            /* dst_mask */
975          TRUE),                 /* pcrel_offset */
976
977   HOWTO (R_ARM_LDR_PC_G2,       /* type */
978          0,                     /* rightshift */
979          2,                     /* size (0 = byte, 1 = short, 2 = long) */
980          32,                    /* bitsize */
981          TRUE,                  /* pc_relative */
982          0,                     /* bitpos */
983          complain_overflow_dont,/* complain_on_overflow */
984          bfd_elf_generic_reloc, /* special_function */
985          "R_ARM_LDR_PC_G2",     /* name */
986          FALSE,                 /* partial_inplace */
987          0xffffffff,            /* src_mask */
988          0xffffffff,            /* dst_mask */
989          TRUE),                 /* pcrel_offset */
990
991   HOWTO (R_ARM_LDRS_PC_G0,      /* type */
992          0,                     /* rightshift */
993          2,                     /* size (0 = byte, 1 = short, 2 = long) */
994          32,                    /* bitsize */
995          TRUE,                  /* pc_relative */
996          0,                     /* bitpos */
997          complain_overflow_dont,/* complain_on_overflow */
998          bfd_elf_generic_reloc, /* special_function */
999          "R_ARM_LDRS_PC_G0",    /* name */
1000          FALSE,                 /* partial_inplace */
1001          0xffffffff,            /* src_mask */
1002          0xffffffff,            /* dst_mask */
1003          TRUE),                 /* pcrel_offset */
1004
1005   HOWTO (R_ARM_LDRS_PC_G1,      /* type */
1006          0,                     /* rightshift */
1007          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1008          32,                    /* bitsize */
1009          TRUE,                  /* pc_relative */
1010          0,                     /* bitpos */
1011          complain_overflow_dont,/* complain_on_overflow */
1012          bfd_elf_generic_reloc, /* special_function */
1013          "R_ARM_LDRS_PC_G1",    /* name */
1014          FALSE,                 /* partial_inplace */
1015          0xffffffff,            /* src_mask */
1016          0xffffffff,            /* dst_mask */
1017          TRUE),                 /* pcrel_offset */
1018
1019   HOWTO (R_ARM_LDRS_PC_G2,      /* type */
1020          0,                     /* rightshift */
1021          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1022          32,                    /* bitsize */
1023          TRUE,                  /* pc_relative */
1024          0,                     /* bitpos */
1025          complain_overflow_dont,/* complain_on_overflow */
1026          bfd_elf_generic_reloc, /* special_function */
1027          "R_ARM_LDRS_PC_G2",    /* name */
1028          FALSE,                 /* partial_inplace */
1029          0xffffffff,            /* src_mask */
1030          0xffffffff,            /* dst_mask */
1031          TRUE),                 /* pcrel_offset */
1032
1033   HOWTO (R_ARM_LDC_PC_G0,       /* type */
1034          0,                     /* rightshift */
1035          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1036          32,                    /* bitsize */
1037          TRUE,                  /* pc_relative */
1038          0,                     /* bitpos */
1039          complain_overflow_dont,/* complain_on_overflow */
1040          bfd_elf_generic_reloc, /* special_function */
1041          "R_ARM_LDC_PC_G0",     /* name */
1042          FALSE,                 /* partial_inplace */
1043          0xffffffff,            /* src_mask */
1044          0xffffffff,            /* dst_mask */
1045          TRUE),                 /* pcrel_offset */
1046
1047   HOWTO (R_ARM_LDC_PC_G1,       /* type */
1048          0,                     /* rightshift */
1049          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1050          32,                    /* bitsize */
1051          TRUE,                  /* pc_relative */
1052          0,                     /* bitpos */
1053          complain_overflow_dont,/* complain_on_overflow */
1054          bfd_elf_generic_reloc, /* special_function */
1055          "R_ARM_LDC_PC_G1",     /* name */
1056          FALSE,                 /* partial_inplace */
1057          0xffffffff,            /* src_mask */
1058          0xffffffff,            /* dst_mask */
1059          TRUE),                 /* pcrel_offset */
1060
1061   HOWTO (R_ARM_LDC_PC_G2,       /* type */
1062          0,                     /* rightshift */
1063          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1064          32,                    /* bitsize */
1065          TRUE,                  /* pc_relative */
1066          0,                     /* bitpos */
1067          complain_overflow_dont,/* complain_on_overflow */
1068          bfd_elf_generic_reloc, /* special_function */
1069          "R_ARM_LDC_PC_G2",     /* name */
1070          FALSE,                 /* partial_inplace */
1071          0xffffffff,            /* src_mask */
1072          0xffffffff,            /* dst_mask */
1073          TRUE),                 /* pcrel_offset */
1074
1075   HOWTO (R_ARM_ALU_SB_G0_NC,    /* type */
1076          0,                     /* rightshift */
1077          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1078          32,                    /* bitsize */
1079          TRUE,                  /* pc_relative */
1080          0,                     /* bitpos */
1081          complain_overflow_dont,/* complain_on_overflow */
1082          bfd_elf_generic_reloc, /* special_function */
1083          "R_ARM_ALU_SB_G0_NC",  /* name */
1084          FALSE,                 /* partial_inplace */
1085          0xffffffff,            /* src_mask */
1086          0xffffffff,            /* dst_mask */
1087          TRUE),                 /* pcrel_offset */
1088
1089   HOWTO (R_ARM_ALU_SB_G0,       /* type */
1090          0,                     /* rightshift */
1091          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1092          32,                    /* bitsize */
1093          TRUE,                  /* pc_relative */
1094          0,                     /* bitpos */
1095          complain_overflow_dont,/* complain_on_overflow */
1096          bfd_elf_generic_reloc, /* special_function */
1097          "R_ARM_ALU_SB_G0",     /* name */
1098          FALSE,                 /* partial_inplace */
1099          0xffffffff,            /* src_mask */
1100          0xffffffff,            /* dst_mask */
1101          TRUE),                 /* pcrel_offset */
1102
1103   HOWTO (R_ARM_ALU_SB_G1_NC,    /* type */
1104          0,                     /* rightshift */
1105          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1106          32,                    /* bitsize */
1107          TRUE,                  /* pc_relative */
1108          0,                     /* bitpos */
1109          complain_overflow_dont,/* complain_on_overflow */
1110          bfd_elf_generic_reloc, /* special_function */
1111          "R_ARM_ALU_SB_G1_NC",  /* name */
1112          FALSE,                 /* partial_inplace */
1113          0xffffffff,            /* src_mask */
1114          0xffffffff,            /* dst_mask */
1115          TRUE),                 /* pcrel_offset */
1116
1117   HOWTO (R_ARM_ALU_SB_G1,       /* type */
1118          0,                     /* rightshift */
1119          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1120          32,                    /* bitsize */
1121          TRUE,                  /* pc_relative */
1122          0,                     /* bitpos */
1123          complain_overflow_dont,/* complain_on_overflow */
1124          bfd_elf_generic_reloc, /* special_function */
1125          "R_ARM_ALU_SB_G1",     /* name */
1126          FALSE,                 /* partial_inplace */
1127          0xffffffff,            /* src_mask */
1128          0xffffffff,            /* dst_mask */
1129          TRUE),                 /* pcrel_offset */
1130
1131   HOWTO (R_ARM_ALU_SB_G2,       /* type */
1132          0,                     /* rightshift */
1133          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1134          32,                    /* bitsize */
1135          TRUE,                  /* pc_relative */
1136          0,                     /* bitpos */
1137          complain_overflow_dont,/* complain_on_overflow */
1138          bfd_elf_generic_reloc, /* special_function */
1139          "R_ARM_ALU_SB_G2",     /* name */
1140          FALSE,                 /* partial_inplace */
1141          0xffffffff,            /* src_mask */
1142          0xffffffff,            /* dst_mask */
1143          TRUE),                 /* pcrel_offset */
1144
1145   HOWTO (R_ARM_LDR_SB_G0,       /* type */
1146          0,                     /* rightshift */
1147          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1148          32,                    /* bitsize */
1149          TRUE,                  /* pc_relative */
1150          0,                     /* bitpos */
1151          complain_overflow_dont,/* complain_on_overflow */
1152          bfd_elf_generic_reloc, /* special_function */
1153          "R_ARM_LDR_SB_G0",     /* name */
1154          FALSE,                 /* partial_inplace */
1155          0xffffffff,            /* src_mask */
1156          0xffffffff,            /* dst_mask */
1157          TRUE),                 /* pcrel_offset */
1158
1159   HOWTO (R_ARM_LDR_SB_G1,       /* type */
1160          0,                     /* rightshift */
1161          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1162          32,                    /* bitsize */
1163          TRUE,                  /* pc_relative */
1164          0,                     /* bitpos */
1165          complain_overflow_dont,/* complain_on_overflow */
1166          bfd_elf_generic_reloc, /* special_function */
1167          "R_ARM_LDR_SB_G1",     /* name */
1168          FALSE,                 /* partial_inplace */
1169          0xffffffff,            /* src_mask */
1170          0xffffffff,            /* dst_mask */
1171          TRUE),                 /* pcrel_offset */
1172
1173   HOWTO (R_ARM_LDR_SB_G2,       /* type */
1174          0,                     /* rightshift */
1175          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1176          32,                    /* bitsize */
1177          TRUE,                  /* pc_relative */
1178          0,                     /* bitpos */
1179          complain_overflow_dont,/* complain_on_overflow */
1180          bfd_elf_generic_reloc, /* special_function */
1181          "R_ARM_LDR_SB_G2",     /* name */
1182          FALSE,                 /* partial_inplace */
1183          0xffffffff,            /* src_mask */
1184          0xffffffff,            /* dst_mask */
1185          TRUE),                 /* pcrel_offset */
1186
1187   HOWTO (R_ARM_LDRS_SB_G0,      /* type */
1188          0,                     /* rightshift */
1189          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1190          32,                    /* bitsize */
1191          TRUE,                  /* pc_relative */
1192          0,                     /* bitpos */
1193          complain_overflow_dont,/* complain_on_overflow */
1194          bfd_elf_generic_reloc, /* special_function */
1195          "R_ARM_LDRS_SB_G0",    /* name */
1196          FALSE,                 /* partial_inplace */
1197          0xffffffff,            /* src_mask */
1198          0xffffffff,            /* dst_mask */
1199          TRUE),                 /* pcrel_offset */
1200
1201   HOWTO (R_ARM_LDRS_SB_G1,      /* type */
1202          0,                     /* rightshift */
1203          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1204          32,                    /* bitsize */
1205          TRUE,                  /* pc_relative */
1206          0,                     /* bitpos */
1207          complain_overflow_dont,/* complain_on_overflow */
1208          bfd_elf_generic_reloc, /* special_function */
1209          "R_ARM_LDRS_SB_G1",    /* name */
1210          FALSE,                 /* partial_inplace */
1211          0xffffffff,            /* src_mask */
1212          0xffffffff,            /* dst_mask */
1213          TRUE),                 /* pcrel_offset */
1214
1215   HOWTO (R_ARM_LDRS_SB_G2,      /* type */
1216          0,                     /* rightshift */
1217          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1218          32,                    /* bitsize */
1219          TRUE,                  /* pc_relative */
1220          0,                     /* bitpos */
1221          complain_overflow_dont,/* complain_on_overflow */
1222          bfd_elf_generic_reloc, /* special_function */
1223          "R_ARM_LDRS_SB_G2",    /* name */
1224          FALSE,                 /* partial_inplace */
1225          0xffffffff,            /* src_mask */
1226          0xffffffff,            /* dst_mask */
1227          TRUE),                 /* pcrel_offset */
1228
1229   HOWTO (R_ARM_LDC_SB_G0,       /* type */
1230          0,                     /* rightshift */
1231          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1232          32,                    /* bitsize */
1233          TRUE,                  /* pc_relative */
1234          0,                     /* bitpos */
1235          complain_overflow_dont,/* complain_on_overflow */
1236          bfd_elf_generic_reloc, /* special_function */
1237          "R_ARM_LDC_SB_G0",     /* name */
1238          FALSE,                 /* partial_inplace */
1239          0xffffffff,            /* src_mask */
1240          0xffffffff,            /* dst_mask */
1241          TRUE),                 /* pcrel_offset */
1242
1243   HOWTO (R_ARM_LDC_SB_G1,       /* type */
1244          0,                     /* rightshift */
1245          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1246          32,                    /* bitsize */
1247          TRUE,                  /* pc_relative */
1248          0,                     /* bitpos */
1249          complain_overflow_dont,/* complain_on_overflow */
1250          bfd_elf_generic_reloc, /* special_function */
1251          "R_ARM_LDC_SB_G1",     /* name */
1252          FALSE,                 /* partial_inplace */
1253          0xffffffff,            /* src_mask */
1254          0xffffffff,            /* dst_mask */
1255          TRUE),                 /* pcrel_offset */
1256
1257   HOWTO (R_ARM_LDC_SB_G2,       /* type */
1258          0,                     /* rightshift */
1259          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1260          32,                    /* bitsize */
1261          TRUE,                  /* pc_relative */
1262          0,                     /* bitpos */
1263          complain_overflow_dont,/* complain_on_overflow */
1264          bfd_elf_generic_reloc, /* special_function */
1265          "R_ARM_LDC_SB_G2",     /* name */
1266          FALSE,                 /* partial_inplace */
1267          0xffffffff,            /* src_mask */
1268          0xffffffff,            /* dst_mask */
1269          TRUE),                 /* pcrel_offset */
1270
1271   /* End of group relocations.  */
1272
1273   HOWTO (R_ARM_MOVW_BREL_NC,    /* type */
1274          0,                     /* rightshift */
1275          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1276          16,                    /* bitsize */
1277          FALSE,                 /* pc_relative */
1278          0,                     /* bitpos */
1279          complain_overflow_dont,/* complain_on_overflow */
1280          bfd_elf_generic_reloc, /* special_function */
1281          "R_ARM_MOVW_BREL_NC",  /* name */
1282          FALSE,                 /* partial_inplace */
1283          0x0000ffff,            /* src_mask */
1284          0x0000ffff,            /* dst_mask */
1285          FALSE),                /* pcrel_offset */
1286
1287   HOWTO (R_ARM_MOVT_BREL,       /* type */
1288          0,                     /* rightshift */
1289          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1290          16,                    /* bitsize */
1291          FALSE,                 /* pc_relative */
1292          0,                     /* bitpos */
1293          complain_overflow_bitfield,/* complain_on_overflow */
1294          bfd_elf_generic_reloc, /* special_function */
1295          "R_ARM_MOVT_BREL",     /* name */
1296          FALSE,                 /* partial_inplace */
1297          0x0000ffff,            /* src_mask */
1298          0x0000ffff,            /* dst_mask */
1299          FALSE),                /* pcrel_offset */
1300
1301   HOWTO (R_ARM_MOVW_BREL,       /* type */
1302          0,                     /* rightshift */
1303          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1304          16,                    /* bitsize */
1305          FALSE,                 /* pc_relative */
1306          0,                     /* bitpos */
1307          complain_overflow_dont,/* complain_on_overflow */
1308          bfd_elf_generic_reloc, /* special_function */
1309          "R_ARM_MOVW_BREL",     /* name */
1310          FALSE,                 /* partial_inplace */
1311          0x0000ffff,            /* src_mask */
1312          0x0000ffff,            /* dst_mask */
1313          FALSE),                /* pcrel_offset */
1314
1315   HOWTO (R_ARM_THM_MOVW_BREL_NC,/* type */
1316          0,                     /* rightshift */
1317          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1318          16,                    /* bitsize */
1319          FALSE,                 /* pc_relative */
1320          0,                     /* bitpos */
1321          complain_overflow_dont,/* complain_on_overflow */
1322          bfd_elf_generic_reloc, /* special_function */
1323          "R_ARM_THM_MOVW_BREL_NC",/* name */
1324          FALSE,                 /* partial_inplace */
1325          0x040f70ff,            /* src_mask */
1326          0x040f70ff,            /* dst_mask */
1327          FALSE),                /* pcrel_offset */
1328
1329   HOWTO (R_ARM_THM_MOVT_BREL,   /* type */
1330          0,                     /* rightshift */
1331          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1332          16,                    /* bitsize */
1333          FALSE,                 /* pc_relative */
1334          0,                     /* bitpos */
1335          complain_overflow_bitfield,/* complain_on_overflow */
1336          bfd_elf_generic_reloc, /* special_function */
1337          "R_ARM_THM_MOVT_BREL", /* name */
1338          FALSE,                 /* partial_inplace */
1339          0x040f70ff,            /* src_mask */
1340          0x040f70ff,            /* dst_mask */
1341          FALSE),                /* pcrel_offset */
1342
1343   HOWTO (R_ARM_THM_MOVW_BREL,   /* type */
1344          0,                     /* rightshift */
1345          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1346          16,                    /* bitsize */
1347          FALSE,                 /* pc_relative */
1348          0,                     /* bitpos */
1349          complain_overflow_dont,/* complain_on_overflow */
1350          bfd_elf_generic_reloc, /* special_function */
1351          "R_ARM_THM_MOVW_BREL", /* name */
1352          FALSE,                 /* partial_inplace */
1353          0x040f70ff,            /* src_mask */
1354          0x040f70ff,            /* dst_mask */
1355          FALSE),                /* pcrel_offset */
1356
1357   EMPTY_HOWTO (90),   /* unallocated */
1358   EMPTY_HOWTO (91),
1359   EMPTY_HOWTO (92),
1360   EMPTY_HOWTO (93),
1361
1362   HOWTO (R_ARM_PLT32_ABS,       /* type */
1363          0,                     /* rightshift */
1364          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1365          32,                    /* bitsize */
1366          FALSE,                 /* pc_relative */
1367          0,                     /* bitpos */
1368          complain_overflow_dont,/* complain_on_overflow */
1369          bfd_elf_generic_reloc, /* special_function */
1370          "R_ARM_PLT32_ABS",     /* name */
1371          FALSE,                 /* partial_inplace */
1372          0xffffffff,            /* src_mask */
1373          0xffffffff,            /* dst_mask */
1374          FALSE),                /* pcrel_offset */
1375
1376   HOWTO (R_ARM_GOT_ABS,         /* type */
1377          0,                     /* rightshift */
1378          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1379          32,                    /* bitsize */
1380          FALSE,                 /* pc_relative */
1381          0,                     /* bitpos */
1382          complain_overflow_dont,/* complain_on_overflow */
1383          bfd_elf_generic_reloc, /* special_function */
1384          "R_ARM_GOT_ABS",       /* name */
1385          FALSE,                 /* partial_inplace */
1386          0xffffffff,            /* src_mask */
1387          0xffffffff,            /* dst_mask */
1388          FALSE),                        /* pcrel_offset */
1389
1390   HOWTO (R_ARM_GOT_PREL,        /* type */
1391          0,                     /* rightshift */
1392          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1393          32,                    /* bitsize */
1394          TRUE,                  /* pc_relative */
1395          0,                     /* bitpos */
1396          complain_overflow_dont,        /* complain_on_overflow */
1397          bfd_elf_generic_reloc, /* special_function */
1398          "R_ARM_GOT_PREL",      /* name */
1399          FALSE,                 /* partial_inplace */
1400          0xffffffff,            /* src_mask */
1401          0xffffffff,            /* dst_mask */
1402          TRUE),                 /* pcrel_offset */
1403
1404   HOWTO (R_ARM_GOT_BREL12,      /* type */
1405          0,                     /* rightshift */
1406          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1407          12,                    /* bitsize */
1408          FALSE,                 /* pc_relative */
1409          0,                     /* bitpos */
1410          complain_overflow_bitfield,/* complain_on_overflow */
1411          bfd_elf_generic_reloc, /* special_function */
1412          "R_ARM_GOT_BREL12",    /* name */
1413          FALSE,                 /* partial_inplace */
1414          0x00000fff,            /* src_mask */
1415          0x00000fff,            /* dst_mask */
1416          FALSE),                /* pcrel_offset */
1417
1418   HOWTO (R_ARM_GOTOFF12,        /* type */
1419          0,                     /* rightshift */
1420          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1421          12,                    /* bitsize */
1422          FALSE,                 /* pc_relative */
1423          0,                     /* bitpos */
1424          complain_overflow_bitfield,/* complain_on_overflow */
1425          bfd_elf_generic_reloc, /* special_function */
1426          "R_ARM_GOTOFF12",      /* name */
1427          FALSE,                 /* partial_inplace */
1428          0x00000fff,            /* src_mask */
1429          0x00000fff,            /* dst_mask */
1430          FALSE),                /* pcrel_offset */
1431
1432   EMPTY_HOWTO (R_ARM_GOTRELAX),  /* reserved for future GOT-load optimizations */
1433
1434   /* GNU extension to record C++ vtable member usage */
1435   HOWTO (R_ARM_GNU_VTENTRY,     /* type */
1436          0,                     /* rightshift */
1437          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1438          0,                     /* bitsize */
1439          FALSE,                 /* pc_relative */
1440          0,                     /* bitpos */
1441          complain_overflow_dont, /* complain_on_overflow */
1442          _bfd_elf_rel_vtable_reloc_fn,  /* special_function */
1443          "R_ARM_GNU_VTENTRY",   /* name */
1444          FALSE,                 /* partial_inplace */
1445          0,                     /* src_mask */
1446          0,                     /* dst_mask */
1447          FALSE),                /* pcrel_offset */
1448
1449   /* GNU extension to record C++ vtable hierarchy */
1450   HOWTO (R_ARM_GNU_VTINHERIT, /* type */
1451          0,                     /* rightshift */
1452          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1453          0,                     /* bitsize */
1454          FALSE,                 /* pc_relative */
1455          0,                     /* bitpos */
1456          complain_overflow_dont, /* complain_on_overflow */
1457          NULL,                  /* special_function */
1458          "R_ARM_GNU_VTINHERIT", /* name */
1459          FALSE,                 /* partial_inplace */
1460          0,                     /* src_mask */
1461          0,                     /* dst_mask */
1462          FALSE),                /* pcrel_offset */
1463
1464   HOWTO (R_ARM_THM_JUMP11,      /* type */
1465          1,                     /* rightshift */
1466          1,                     /* size (0 = byte, 1 = short, 2 = long) */
1467          11,                    /* bitsize */
1468          TRUE,                  /* pc_relative */
1469          0,                     /* bitpos */
1470          complain_overflow_signed,      /* complain_on_overflow */
1471          bfd_elf_generic_reloc, /* special_function */
1472          "R_ARM_THM_JUMP11",    /* name */
1473          FALSE,                 /* partial_inplace */
1474          0x000007ff,            /* src_mask */
1475          0x000007ff,            /* dst_mask */
1476          TRUE),                 /* pcrel_offset */
1477
1478   HOWTO (R_ARM_THM_JUMP8,       /* type */
1479          1,                     /* rightshift */
1480          1,                     /* size (0 = byte, 1 = short, 2 = long) */
1481          8,                     /* bitsize */
1482          TRUE,                  /* pc_relative */
1483          0,                     /* bitpos */
1484          complain_overflow_signed,      /* complain_on_overflow */
1485          bfd_elf_generic_reloc, /* special_function */
1486          "R_ARM_THM_JUMP8",     /* name */
1487          FALSE,                 /* partial_inplace */
1488          0x000000ff,            /* src_mask */
1489          0x000000ff,            /* dst_mask */
1490          TRUE),                 /* pcrel_offset */
1491
1492   /* TLS relocations */
1493   HOWTO (R_ARM_TLS_GD32,        /* type */
1494          0,                     /* rightshift */
1495          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1496          32,                    /* bitsize */
1497          FALSE,                 /* pc_relative */
1498          0,                     /* bitpos */
1499          complain_overflow_bitfield,/* complain_on_overflow */
1500          NULL,                  /* special_function */
1501          "R_ARM_TLS_GD32",      /* name */
1502          TRUE,                  /* partial_inplace */
1503          0xffffffff,            /* src_mask */
1504          0xffffffff,            /* dst_mask */
1505          FALSE),                /* pcrel_offset */
1506
1507   HOWTO (R_ARM_TLS_LDM32,       /* type */
1508          0,                     /* rightshift */
1509          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1510          32,                    /* bitsize */
1511          FALSE,                 /* pc_relative */
1512          0,                     /* bitpos */
1513          complain_overflow_bitfield,/* complain_on_overflow */
1514          bfd_elf_generic_reloc, /* special_function */
1515          "R_ARM_TLS_LDM32",     /* name */
1516          TRUE,                  /* partial_inplace */
1517          0xffffffff,            /* src_mask */
1518          0xffffffff,            /* dst_mask */
1519          FALSE),                /* pcrel_offset */
1520
1521   HOWTO (R_ARM_TLS_LDO32,       /* type */
1522          0,                     /* rightshift */
1523          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1524          32,                    /* bitsize */
1525          FALSE,                 /* pc_relative */
1526          0,                     /* bitpos */
1527          complain_overflow_bitfield,/* complain_on_overflow */
1528          bfd_elf_generic_reloc, /* special_function */
1529          "R_ARM_TLS_LDO32",     /* name */
1530          TRUE,                  /* partial_inplace */
1531          0xffffffff,            /* src_mask */
1532          0xffffffff,            /* dst_mask */
1533          FALSE),                /* pcrel_offset */
1534
1535   HOWTO (R_ARM_TLS_IE32,        /* type */
1536          0,                     /* rightshift */
1537          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1538          32,                    /* bitsize */
1539          FALSE,                  /* pc_relative */
1540          0,                     /* bitpos */
1541          complain_overflow_bitfield,/* complain_on_overflow */
1542          NULL,                  /* special_function */
1543          "R_ARM_TLS_IE32",      /* name */
1544          TRUE,                  /* partial_inplace */
1545          0xffffffff,            /* src_mask */
1546          0xffffffff,            /* dst_mask */
1547          FALSE),                /* pcrel_offset */
1548
1549   HOWTO (R_ARM_TLS_LE32,        /* type */
1550          0,                     /* rightshift */
1551          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1552          32,                    /* bitsize */
1553          FALSE,                 /* pc_relative */
1554          0,                     /* bitpos */
1555          complain_overflow_bitfield,/* complain_on_overflow */
1556          bfd_elf_generic_reloc, /* special_function */
1557          "R_ARM_TLS_LE32",      /* name */
1558          TRUE,                  /* partial_inplace */
1559          0xffffffff,            /* src_mask */
1560          0xffffffff,            /* dst_mask */
1561          FALSE),                /* pcrel_offset */
1562
1563   HOWTO (R_ARM_TLS_LDO12,       /* type */
1564          0,                     /* rightshift */
1565          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1566          12,                    /* bitsize */
1567          FALSE,                 /* pc_relative */
1568          0,                     /* bitpos */
1569          complain_overflow_bitfield,/* complain_on_overflow */
1570          bfd_elf_generic_reloc, /* special_function */
1571          "R_ARM_TLS_LDO12",     /* name */
1572          FALSE,                 /* partial_inplace */
1573          0x00000fff,            /* src_mask */
1574          0x00000fff,            /* dst_mask */
1575          FALSE),                /* pcrel_offset */
1576
1577   HOWTO (R_ARM_TLS_LE12,        /* type */
1578          0,                     /* rightshift */
1579          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1580          12,                    /* bitsize */
1581          FALSE,                 /* pc_relative */
1582          0,                     /* bitpos */
1583          complain_overflow_bitfield,/* complain_on_overflow */
1584          bfd_elf_generic_reloc, /* special_function */
1585          "R_ARM_TLS_LE12",      /* name */
1586          FALSE,                 /* partial_inplace */
1587          0x00000fff,            /* src_mask */
1588          0x00000fff,            /* dst_mask */
1589          FALSE),                /* pcrel_offset */
1590
1591   HOWTO (R_ARM_TLS_IE12GP,      /* type */
1592          0,                     /* rightshift */
1593          2,                     /* size (0 = byte, 1 = short, 2 = long) */
1594          12,                    /* bitsize */
1595          FALSE,                 /* pc_relative */
1596          0,                     /* bitpos */
1597          complain_overflow_bitfield,/* complain_on_overflow */
1598          bfd_elf_generic_reloc, /* special_function */
1599          "R_ARM_TLS_IE12GP",    /* name */
1600          FALSE,                 /* partial_inplace */
1601          0x00000fff,            /* src_mask */
1602          0x00000fff,            /* dst_mask */
1603          FALSE),                /* pcrel_offset */
1604 };
1605
1606 /* 112-127 private relocations
1607    128 R_ARM_ME_TOO, obsolete
1608    129-255 unallocated in AAELF.
1609
1610    249-255 extended, currently unused, relocations:  */
1611
1612 static reloc_howto_type elf32_arm_howto_table_2[4] =
1613 {
1614   HOWTO (R_ARM_RREL32,          /* type */
1615          0,                     /* rightshift */
1616          0,                     /* size (0 = byte, 1 = short, 2 = long) */
1617          0,                     /* bitsize */
1618          FALSE,                 /* pc_relative */
1619          0,                     /* bitpos */
1620          complain_overflow_dont,/* complain_on_overflow */
1621          bfd_elf_generic_reloc, /* special_function */
1622          "R_ARM_RREL32",        /* name */
1623          FALSE,                 /* partial_inplace */
1624          0,                     /* src_mask */
1625          0,                     /* dst_mask */
1626          FALSE),                /* pcrel_offset */
1627
1628   HOWTO (R_ARM_RABS32,          /* type */
1629          0,                     /* rightshift */
1630          0,                     /* size (0 = byte, 1 = short, 2 = long) */
1631          0,                     /* bitsize */
1632          FALSE,                 /* pc_relative */
1633          0,                     /* bitpos */
1634          complain_overflow_dont,/* complain_on_overflow */
1635          bfd_elf_generic_reloc, /* special_function */
1636          "R_ARM_RABS32",        /* name */
1637          FALSE,                 /* partial_inplace */
1638          0,                     /* src_mask */
1639          0,                     /* dst_mask */
1640          FALSE),                /* pcrel_offset */
1641
1642   HOWTO (R_ARM_RPC24,           /* type */
1643          0,                     /* rightshift */
1644          0,                     /* size (0 = byte, 1 = short, 2 = long) */
1645          0,                     /* bitsize */
1646          FALSE,                 /* pc_relative */
1647          0,                     /* bitpos */
1648          complain_overflow_dont,/* complain_on_overflow */
1649          bfd_elf_generic_reloc, /* special_function */
1650          "R_ARM_RPC24",         /* name */
1651          FALSE,                 /* partial_inplace */
1652          0,                     /* src_mask */
1653          0,                     /* dst_mask */
1654          FALSE),                /* pcrel_offset */
1655
1656   HOWTO (R_ARM_RBASE,           /* type */
1657          0,                     /* rightshift */
1658          0,                     /* size (0 = byte, 1 = short, 2 = long) */
1659          0,                     /* bitsize */
1660          FALSE,                 /* pc_relative */
1661          0,                     /* bitpos */
1662          complain_overflow_dont,/* complain_on_overflow */
1663          bfd_elf_generic_reloc, /* special_function */
1664          "R_ARM_RBASE",         /* name */
1665          FALSE,                 /* partial_inplace */
1666          0,                     /* src_mask */
1667          0,                     /* dst_mask */
1668          FALSE)                 /* pcrel_offset */
1669 };
1670
1671 static reloc_howto_type *
1672 elf32_arm_howto_from_type (unsigned int r_type)
1673 {
1674   if (r_type < NUM_ELEM (elf32_arm_howto_table_1))
1675     return &elf32_arm_howto_table_1[r_type];
1676
1677   if (r_type >= R_ARM_RREL32
1678       && r_type < R_ARM_RREL32 + NUM_ELEM (elf32_arm_howto_table_2))
1679     return &elf32_arm_howto_table_2[r_type - R_ARM_RREL32];
1680
1681   return NULL;
1682 }
1683
1684 static void
1685 elf32_arm_info_to_howto (bfd * abfd ATTRIBUTE_UNUSED, arelent * bfd_reloc,
1686                          Elf_Internal_Rela * elf_reloc)
1687 {
1688   unsigned int r_type;
1689
1690   r_type = ELF32_R_TYPE (elf_reloc->r_info);
1691   bfd_reloc->howto = elf32_arm_howto_from_type (r_type);
1692 }
1693
1694 struct elf32_arm_reloc_map
1695   {
1696     bfd_reloc_code_real_type  bfd_reloc_val;
1697     unsigned char             elf_reloc_val;
1698   };
1699
1700 /* All entries in this list must also be present in elf32_arm_howto_table.  */
1701 static const struct elf32_arm_reloc_map elf32_arm_reloc_map[] =
1702   {
1703     {BFD_RELOC_NONE,                 R_ARM_NONE},
1704     {BFD_RELOC_ARM_PCREL_BRANCH,     R_ARM_PC24},
1705     {BFD_RELOC_ARM_PCREL_CALL,       R_ARM_CALL},
1706     {BFD_RELOC_ARM_PCREL_JUMP,       R_ARM_JUMP24},
1707     {BFD_RELOC_ARM_PCREL_BLX,        R_ARM_XPC25},
1708     {BFD_RELOC_THUMB_PCREL_BLX,      R_ARM_THM_XPC22},
1709     {BFD_RELOC_32,                   R_ARM_ABS32},
1710     {BFD_RELOC_32_PCREL,             R_ARM_REL32},
1711     {BFD_RELOC_8,                    R_ARM_ABS8},
1712     {BFD_RELOC_16,                   R_ARM_ABS16},
1713     {BFD_RELOC_ARM_OFFSET_IMM,       R_ARM_ABS12},
1714     {BFD_RELOC_ARM_THUMB_OFFSET,     R_ARM_THM_ABS5},
1715     {BFD_RELOC_THUMB_PCREL_BRANCH25, R_ARM_THM_JUMP24},
1716     {BFD_RELOC_THUMB_PCREL_BRANCH23, R_ARM_THM_CALL},
1717     {BFD_RELOC_THUMB_PCREL_BRANCH12, R_ARM_THM_JUMP11},
1718     {BFD_RELOC_THUMB_PCREL_BRANCH20, R_ARM_THM_JUMP19},
1719     {BFD_RELOC_THUMB_PCREL_BRANCH9,  R_ARM_THM_JUMP8},
1720     {BFD_RELOC_THUMB_PCREL_BRANCH7,  R_ARM_THM_JUMP6},
1721     {BFD_RELOC_ARM_GLOB_DAT,         R_ARM_GLOB_DAT},
1722     {BFD_RELOC_ARM_JUMP_SLOT,        R_ARM_JUMP_SLOT},
1723     {BFD_RELOC_ARM_RELATIVE,         R_ARM_RELATIVE},
1724     {BFD_RELOC_ARM_GOTOFF,           R_ARM_GOTOFF32},
1725     {BFD_RELOC_ARM_GOTPC,            R_ARM_GOTPC},
1726     {BFD_RELOC_ARM_GOT32,            R_ARM_GOT32},
1727     {BFD_RELOC_ARM_PLT32,            R_ARM_PLT32},
1728     {BFD_RELOC_ARM_TARGET1,          R_ARM_TARGET1},
1729     {BFD_RELOC_ARM_ROSEGREL32,       R_ARM_ROSEGREL32},
1730     {BFD_RELOC_ARM_SBREL32,          R_ARM_SBREL32},
1731     {BFD_RELOC_ARM_PREL31,           R_ARM_PREL31},
1732     {BFD_RELOC_ARM_TARGET2,          R_ARM_TARGET2},
1733     {BFD_RELOC_ARM_PLT32,            R_ARM_PLT32},
1734     {BFD_RELOC_ARM_TLS_GD32,         R_ARM_TLS_GD32},
1735     {BFD_RELOC_ARM_TLS_LDO32,        R_ARM_TLS_LDO32},
1736     {BFD_RELOC_ARM_TLS_LDM32,        R_ARM_TLS_LDM32},
1737     {BFD_RELOC_ARM_TLS_DTPMOD32,     R_ARM_TLS_DTPMOD32},
1738     {BFD_RELOC_ARM_TLS_DTPOFF32,     R_ARM_TLS_DTPOFF32},
1739     {BFD_RELOC_ARM_TLS_TPOFF32,      R_ARM_TLS_TPOFF32},
1740     {BFD_RELOC_ARM_TLS_IE32,         R_ARM_TLS_IE32},
1741     {BFD_RELOC_ARM_TLS_LE32,         R_ARM_TLS_LE32},
1742     {BFD_RELOC_VTABLE_INHERIT,       R_ARM_GNU_VTINHERIT},
1743     {BFD_RELOC_VTABLE_ENTRY,         R_ARM_GNU_VTENTRY},
1744     {BFD_RELOC_ARM_MOVW,             R_ARM_MOVW_ABS_NC},
1745     {BFD_RELOC_ARM_MOVT,             R_ARM_MOVT_ABS},
1746     {BFD_RELOC_ARM_MOVW_PCREL,       R_ARM_MOVW_PREL_NC},
1747     {BFD_RELOC_ARM_MOVT_PCREL,       R_ARM_MOVT_PREL},
1748     {BFD_RELOC_ARM_THUMB_MOVW,       R_ARM_THM_MOVW_ABS_NC},
1749     {BFD_RELOC_ARM_THUMB_MOVT,       R_ARM_THM_MOVT_ABS},
1750     {BFD_RELOC_ARM_THUMB_MOVW_PCREL, R_ARM_THM_MOVW_PREL_NC},
1751     {BFD_RELOC_ARM_THUMB_MOVT_PCREL, R_ARM_THM_MOVT_PREL},
1752     {BFD_RELOC_ARM_ALU_PC_G0_NC, R_ARM_ALU_PC_G0_NC},
1753     {BFD_RELOC_ARM_ALU_PC_G0, R_ARM_ALU_PC_G0},
1754     {BFD_RELOC_ARM_ALU_PC_G1_NC, R_ARM_ALU_PC_G1_NC},
1755     {BFD_RELOC_ARM_ALU_PC_G1, R_ARM_ALU_PC_G1},
1756     {BFD_RELOC_ARM_ALU_PC_G2, R_ARM_ALU_PC_G2},
1757     {BFD_RELOC_ARM_LDR_PC_G0, R_ARM_LDR_PC_G0},
1758     {BFD_RELOC_ARM_LDR_PC_G1, R_ARM_LDR_PC_G1},
1759     {BFD_RELOC_ARM_LDR_PC_G2, R_ARM_LDR_PC_G2},
1760     {BFD_RELOC_ARM_LDRS_PC_G0, R_ARM_LDRS_PC_G0},
1761     {BFD_RELOC_ARM_LDRS_PC_G1, R_ARM_LDRS_PC_G1},
1762     {BFD_RELOC_ARM_LDRS_PC_G2, R_ARM_LDRS_PC_G2},
1763     {BFD_RELOC_ARM_LDC_PC_G0, R_ARM_LDC_PC_G0},
1764     {BFD_RELOC_ARM_LDC_PC_G1, R_ARM_LDC_PC_G1},
1765     {BFD_RELOC_ARM_LDC_PC_G2, R_ARM_LDC_PC_G2},
1766     {BFD_RELOC_ARM_ALU_SB_G0_NC, R_ARM_ALU_SB_G0_NC},
1767     {BFD_RELOC_ARM_ALU_SB_G0, R_ARM_ALU_SB_G0},
1768     {BFD_RELOC_ARM_ALU_SB_G1_NC, R_ARM_ALU_SB_G1_NC},
1769     {BFD_RELOC_ARM_ALU_SB_G1, R_ARM_ALU_SB_G1},
1770     {BFD_RELOC_ARM_ALU_SB_G2, R_ARM_ALU_SB_G2},
1771     {BFD_RELOC_ARM_LDR_SB_G0, R_ARM_LDR_SB_G0},
1772     {BFD_RELOC_ARM_LDR_SB_G1, R_ARM_LDR_SB_G1},
1773     {BFD_RELOC_ARM_LDR_SB_G2, R_ARM_LDR_SB_G2},
1774     {BFD_RELOC_ARM_LDRS_SB_G0, R_ARM_LDRS_SB_G0},
1775     {BFD_RELOC_ARM_LDRS_SB_G1, R_ARM_LDRS_SB_G1},
1776     {BFD_RELOC_ARM_LDRS_SB_G2, R_ARM_LDRS_SB_G2},
1777     {BFD_RELOC_ARM_LDC_SB_G0, R_ARM_LDC_SB_G0},
1778     {BFD_RELOC_ARM_LDC_SB_G1, R_ARM_LDC_SB_G1},
1779     {BFD_RELOC_ARM_LDC_SB_G2, R_ARM_LDC_SB_G2}
1780   };
1781
1782 static reloc_howto_type *
1783 elf32_arm_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1784                              bfd_reloc_code_real_type code)
1785 {
1786   unsigned int i;
1787   for (i = 0; i < NUM_ELEM (elf32_arm_reloc_map); i ++)
1788     if (elf32_arm_reloc_map[i].bfd_reloc_val == code)
1789       return elf32_arm_howto_from_type (elf32_arm_reloc_map[i].elf_reloc_val);
1790
1791   return NULL;
1792 }
1793
1794 static reloc_howto_type *
1795 elf32_arm_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1796                              const char *r_name)
1797 {
1798   unsigned int i;
1799
1800   for (i = 0;
1801        i < (sizeof (elf32_arm_howto_table_1)
1802             / sizeof (elf32_arm_howto_table_1[0]));
1803        i++)
1804     if (elf32_arm_howto_table_1[i].name != NULL
1805         && strcasecmp (elf32_arm_howto_table_1[i].name, r_name) == 0)
1806       return &elf32_arm_howto_table_1[i];
1807
1808   for (i = 0;
1809        i < (sizeof (elf32_arm_howto_table_2)
1810             / sizeof (elf32_arm_howto_table_2[0]));
1811        i++)
1812     if (elf32_arm_howto_table_2[i].name != NULL
1813         && strcasecmp (elf32_arm_howto_table_2[i].name, r_name) == 0)
1814       return &elf32_arm_howto_table_2[i];
1815
1816   return NULL;
1817 }
1818
1819 /* Support for core dump NOTE sections */
1820 static bfd_boolean
1821 elf32_arm_nabi_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
1822 {
1823   int offset;
1824   size_t size;
1825
1826   switch (note->descsz)
1827     {
1828       default:
1829         return FALSE;
1830
1831       case 148:         /* Linux/ARM 32-bit*/
1832         /* pr_cursig */
1833         elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
1834
1835         /* pr_pid */
1836         elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
1837
1838         /* pr_reg */
1839         offset = 72;
1840         size = 72;
1841
1842         break;
1843
1844       case 96:          /* FreeBSD/ARM */
1845         /* pr_cursig */
1846         if (elf_tdata(abfd)->core_signal == 0)
1847           elf_tdata (abfd)->core_signal = ((int *)(note->descdata))[5];
1848
1849         /* pr_pid */
1850         elf_tdata (abfd)->core_pid = ((int *)(note->descdata))[6];
1851
1852         /* pr_reg */
1853         offset = 28;
1854         size = 68;
1855         break;
1856     }
1857
1858   /* Make a ".reg/999" section.  */
1859   return _bfd_elfcore_make_pseudosection (abfd, ".reg",
1860                                           size, note->descpos + offset);
1861 }
1862
1863 static bfd_boolean
1864 elf32_arm_nabi_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
1865 {
1866   switch (note->descsz)
1867     {
1868       default:
1869         return FALSE;
1870
1871       case 124:         /* Linux/ARM elf_prpsinfo */
1872         elf_tdata (abfd)->core_program
1873          = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
1874         elf_tdata (abfd)->core_command
1875          = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
1876     }
1877
1878   /* Note that for some reason, a spurious space is tacked
1879      onto the end of the args in some (at least one anyway)
1880      implementations, so strip it off if it exists.  */
1881
1882   {
1883     char *command = elf_tdata (abfd)->core_command;
1884     int n = strlen (command);
1885
1886     if (0 < n && command[n - 1] == ' ')
1887       command[n - 1] = '\0';
1888   }
1889
1890   return TRUE;
1891 }
1892
1893 #define TARGET_LITTLE_SYM               bfd_elf32_littlearm_vec
1894 #define TARGET_LITTLE_NAME              "elf32-littlearm"
1895 #define TARGET_BIG_SYM                  bfd_elf32_bigarm_vec
1896 #define TARGET_BIG_NAME                 "elf32-bigarm"
1897
1898 #define elf_backend_grok_prstatus       elf32_arm_nabi_grok_prstatus
1899 #define elf_backend_grok_psinfo         elf32_arm_nabi_grok_psinfo
1900
1901 typedef unsigned long int insn32;
1902 typedef unsigned short int insn16;
1903
1904 /* In lieu of proper flags, assume all EABIv4 or later objects are
1905    interworkable.  */
1906 #define INTERWORK_FLAG(abfd)  \
1907   (EF_ARM_EABI_VERSION (elf_elfheader (abfd)->e_flags) >= EF_ARM_EABI_VER4 \
1908   || (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK))
1909
1910 /* The linker script knows the section names for placement.
1911    The entry_names are used to do simple name mangling on the stubs.
1912    Given a function name, and its type, the stub can be found. The
1913    name can be changed. The only requirement is the %s be present.  */
1914 #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t"
1915 #define THUMB2ARM_GLUE_ENTRY_NAME   "__%s_from_thumb"
1916
1917 #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7"
1918 #define ARM2THUMB_GLUE_ENTRY_NAME   "__%s_from_arm"
1919
1920 #define VFP11_ERRATUM_VENEER_SECTION_NAME ".vfp11_veneer"
1921 #define VFP11_ERRATUM_VENEER_ENTRY_NAME   "__vfp11_veneer_%x"
1922
1923 /* The name of the dynamic interpreter.  This is put in the .interp
1924    section.  */
1925 #define ELF_DYNAMIC_INTERPRETER     "/usr/lib/ld.so.1"
1926
1927 #ifdef FOUR_WORD_PLT
1928
1929 /* The first entry in a procedure linkage table looks like
1930    this.  It is set up so that any shared library function that is
1931    called before the relocation has been set up calls the dynamic
1932    linker first.  */
1933 static const bfd_vma elf32_arm_plt0_entry [] =
1934   {
1935     0xe52de004,         /* str   lr, [sp, #-4]! */
1936     0xe59fe010,         /* ldr   lr, [pc, #16]  */
1937     0xe08fe00e,         /* add   lr, pc, lr     */
1938     0xe5bef008,         /* ldr   pc, [lr, #8]!  */
1939   };
1940
1941 /* Subsequent entries in a procedure linkage table look like
1942    this.  */
1943 static const bfd_vma elf32_arm_plt_entry [] =
1944   {
1945     0xe28fc600,         /* add   ip, pc, #NN    */
1946     0xe28cca00,         /* add   ip, ip, #NN    */
1947     0xe5bcf000,         /* ldr   pc, [ip, #NN]! */
1948     0x00000000,         /* unused               */
1949   };
1950
1951 #else
1952
1953 /* The first entry in a procedure linkage table looks like
1954    this.  It is set up so that any shared library function that is
1955    called before the relocation has been set up calls the dynamic
1956    linker first.  */
1957 static const bfd_vma elf32_arm_plt0_entry [] =
1958   {
1959     0xe52de004,         /* str   lr, [sp, #-4]! */
1960     0xe59fe004,         /* ldr   lr, [pc, #4]   */
1961     0xe08fe00e,         /* add   lr, pc, lr     */
1962     0xe5bef008,         /* ldr   pc, [lr, #8]!  */
1963     0x00000000,         /* &GOT[0] - .          */
1964   };
1965
1966 /* Subsequent entries in a procedure linkage table look like
1967    this.  */
1968 static const bfd_vma elf32_arm_plt_entry [] =
1969   {
1970     0xe28fc600,         /* add   ip, pc, #0xNN00000 */
1971     0xe28cca00,         /* add   ip, ip, #0xNN000   */
1972     0xe5bcf000,         /* ldr   pc, [ip, #0xNNN]!  */
1973   };
1974
1975 #endif
1976
1977 /* The format of the first entry in the procedure linkage table
1978    for a VxWorks executable.  */
1979 static const bfd_vma elf32_arm_vxworks_exec_plt0_entry[] =
1980   {
1981     0xe52dc008,         /* str    ip,[sp,#-8]!                  */
1982     0xe59fc000,         /* ldr    ip,[pc]                       */
1983     0xe59cf008,         /* ldr    pc,[ip,#8]                    */
1984     0x00000000,         /* .long  _GLOBAL_OFFSET_TABLE_         */
1985   };
1986
1987 /* The format of subsequent entries in a VxWorks executable.  */
1988 static const bfd_vma elf32_arm_vxworks_exec_plt_entry[] =
1989   {
1990     0xe59fc000,         /* ldr    ip,[pc]                       */
1991     0xe59cf000,         /* ldr    pc,[ip]                       */
1992     0x00000000,         /* .long  @got                          */
1993     0xe59fc000,         /* ldr    ip,[pc]                       */
1994     0xea000000,         /* b      _PLT                          */
1995     0x00000000,         /* .long  @pltindex*sizeof(Elf32_Rela)  */
1996   };
1997
1998 /* The format of entries in a VxWorks shared library.  */
1999 static const bfd_vma elf32_arm_vxworks_shared_plt_entry[] =
2000   {
2001     0xe59fc000,         /* ldr    ip,[pc]                       */
2002     0xe79cf009,         /* ldr    pc,[ip,r9]                    */
2003     0x00000000,         /* .long  @got                          */
2004     0xe59fc000,         /* ldr    ip,[pc]                       */
2005     0xe599f008,         /* ldr    pc,[r9,#8]                    */
2006     0x00000000,         /* .long  @pltindex*sizeof(Elf32_Rela)  */
2007   };
2008
2009 /* An initial stub used if the PLT entry is referenced from Thumb code.  */
2010 #define PLT_THUMB_STUB_SIZE 4
2011 static const bfd_vma elf32_arm_plt_thumb_stub [] =
2012   {
2013     0x4778,             /* bx pc */
2014     0x46c0              /* nop   */
2015   };
2016
2017 /* The entries in a PLT when using a DLL-based target with multiple
2018    address spaces.  */
2019 static const bfd_vma elf32_arm_symbian_plt_entry [] = 
2020   {
2021     0xe51ff004,         /* ldr   pc, [pc, #-4] */
2022     0x00000000,         /* dcd   R_ARM_GLOB_DAT(X) */
2023   };
2024
2025 /* Used to build a map of a section.  This is required for mixed-endian
2026    code/data.  */
2027
2028 typedef struct elf32_elf_section_map
2029 {
2030   bfd_vma vma;
2031   char type;
2032 }
2033 elf32_arm_section_map;
2034
2035 /* Information about a VFP11 erratum veneer, or a branch to such a veneer.  */
2036
2037 typedef enum
2038 {
2039   VFP11_ERRATUM_BRANCH_TO_ARM_VENEER,
2040   VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER,
2041   VFP11_ERRATUM_ARM_VENEER,
2042   VFP11_ERRATUM_THUMB_VENEER
2043 }
2044 elf32_vfp11_erratum_type;
2045
2046 typedef struct elf32_vfp11_erratum_list
2047 {
2048   struct elf32_vfp11_erratum_list *next;
2049   bfd_vma vma;
2050   union
2051   {
2052     struct
2053     {
2054       struct elf32_vfp11_erratum_list *veneer;
2055       unsigned int vfp_insn;
2056     } b;
2057     struct
2058     {
2059       struct elf32_vfp11_erratum_list *branch;
2060       unsigned int id;
2061     } v;
2062   } u;
2063   elf32_vfp11_erratum_type type;
2064 }
2065 elf32_vfp11_erratum_list;
2066
2067 typedef struct _arm_elf_section_data
2068 {
2069   struct bfd_elf_section_data elf;
2070   unsigned int mapcount;
2071   unsigned int mapsize;
2072   elf32_arm_section_map *map;
2073   unsigned int erratumcount;
2074   elf32_vfp11_erratum_list *erratumlist;
2075 }
2076 _arm_elf_section_data;
2077
2078 #define elf32_arm_section_data(sec) \
2079   ((_arm_elf_section_data *) elf_section_data (sec))
2080
2081 /* The size of the thread control block.  */
2082 #define TCB_SIZE        8
2083
2084 struct elf32_arm_obj_tdata
2085 {
2086   struct elf_obj_tdata root;
2087
2088   /* tls_type for each local got entry.  */
2089   char *local_got_tls_type;
2090
2091   /* Zero to warn when linking objects with incompatible enum sizes.  */
2092   int no_enum_size_warning;
2093 };
2094
2095 #define elf32_arm_tdata(abfd) \
2096   ((struct elf32_arm_obj_tdata *) (abfd)->tdata.any)
2097
2098 #define elf32_arm_local_got_tls_type(abfd) \
2099   (elf32_arm_tdata (abfd)->local_got_tls_type)
2100
2101 static bfd_boolean
2102 elf32_arm_mkobject (bfd *abfd)
2103 {
2104   if (abfd->tdata.any == NULL)
2105     {
2106       bfd_size_type amt = sizeof (struct elf32_arm_obj_tdata);
2107       abfd->tdata.any = bfd_zalloc (abfd, amt);
2108       if (abfd->tdata.any == NULL)
2109         return FALSE;
2110     }
2111   return bfd_elf_mkobject (abfd);
2112 }
2113
2114 /* The ARM linker needs to keep track of the number of relocs that it
2115    decides to copy in check_relocs for each symbol.  This is so that
2116    it can discard PC relative relocs if it doesn't need them when
2117    linking with -Bsymbolic.  We store the information in a field
2118    extending the regular ELF linker hash table.  */
2119
2120 /* This structure keeps track of the number of relocs we have copied
2121    for a given symbol.  */
2122 struct elf32_arm_relocs_copied
2123   {
2124     /* Next section.  */
2125     struct elf32_arm_relocs_copied * next;
2126     /* A section in dynobj.  */
2127     asection * section;
2128     /* Number of relocs copied in this section.  */
2129     bfd_size_type count;
2130     /* Number of PC-relative relocs copied in this section.  */
2131     bfd_size_type pc_count;
2132   };
2133
2134 #define elf32_arm_hash_entry(ent) ((struct elf32_arm_link_hash_entry *)(ent))
2135
2136 /* Arm ELF linker hash entry.  */
2137 struct elf32_arm_link_hash_entry
2138   {
2139     struct elf_link_hash_entry root;
2140
2141     /* Number of PC relative relocs copied for this symbol.  */
2142     struct elf32_arm_relocs_copied * relocs_copied;
2143
2144     /* We reference count Thumb references to a PLT entry separately,
2145        so that we can emit the Thumb trampoline only if needed.  */
2146     bfd_signed_vma plt_thumb_refcount;
2147
2148     /* Since PLT entries have variable size if the Thumb prologue is
2149        used, we need to record the index into .got.plt instead of
2150        recomputing it from the PLT offset.  */
2151     bfd_signed_vma plt_got_offset;
2152
2153 #define GOT_UNKNOWN     0
2154 #define GOT_NORMAL      1
2155 #define GOT_TLS_GD      2
2156 #define GOT_TLS_IE      4
2157     unsigned char tls_type;
2158
2159     /* The symbol marking the real symbol location for exported thumb
2160        symbols with Arm stubs.  */
2161     struct elf_link_hash_entry *export_glue;
2162   };
2163
2164 /* Traverse an arm ELF linker hash table.  */
2165 #define elf32_arm_link_hash_traverse(table, func, info)                 \
2166   (elf_link_hash_traverse                                               \
2167    (&(table)->root,                                                     \
2168     (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func),    \
2169     (info)))
2170
2171 /* Get the ARM elf linker hash table from a link_info structure.  */
2172 #define elf32_arm_hash_table(info) \
2173   ((struct elf32_arm_link_hash_table *) ((info)->hash))
2174
2175 /* ARM ELF linker hash table.  */
2176 struct elf32_arm_link_hash_table
2177   {
2178     /* The main hash table.  */
2179     struct elf_link_hash_table root;
2180
2181     /* The size in bytes of the section containing the Thumb-to-ARM glue.  */
2182     bfd_size_type thumb_glue_size;
2183
2184     /* The size in bytes of the section containing the ARM-to-Thumb glue.  */
2185     bfd_size_type arm_glue_size;
2186
2187     /* The size in bytes of the section containing glue for VFP11 erratum
2188        veneers.  */
2189     bfd_size_type vfp11_erratum_glue_size;
2190
2191     /* An arbitrary input BFD chosen to hold the glue sections.  */
2192     bfd * bfd_of_glue_owner;
2193
2194     /* Nonzero to output a BE8 image.  */
2195     int byteswap_code;
2196
2197     /* Zero if R_ARM_TARGET1 means R_ARM_ABS32.
2198        Nonzero if R_ARM_TARGET1 means R_ARM_REL32.  */
2199     int target1_is_rel;
2200
2201     /* The relocation to use for R_ARM_TARGET2 relocations.  */
2202     int target2_reloc;
2203
2204     /* Nonzero to fix BX instructions for ARMv4 targets.  */
2205     int fix_v4bx;
2206
2207     /* Nonzero if the ARM/Thumb BLX instructions are available for use.  */
2208     int use_blx;
2209
2210     /* What sort of code sequences we should look for which may trigger the
2211        VFP11 denorm erratum.  */
2212     bfd_arm_vfp11_fix vfp11_fix;
2213
2214     /* Global counter for the number of fixes we have emitted.  */
2215     int num_vfp11_fixes;
2216
2217     /* Nonzero to force PIC branch veneers.  */
2218     int pic_veneer;
2219
2220     /* The number of bytes in the initial entry in the PLT.  */
2221     bfd_size_type plt_header_size;
2222
2223     /* The number of bytes in the subsequent PLT etries.  */
2224     bfd_size_type plt_entry_size;
2225
2226     /* True if the target system is VxWorks.  */
2227     int vxworks_p;
2228
2229     /* True if the target system is Symbian OS.  */
2230     int symbian_p;
2231
2232     /* True if the target uses REL relocations.  */
2233     int use_rel;
2234
2235     /* Short-cuts to get to dynamic linker sections.  */
2236     asection *sgot;
2237     asection *sgotplt;
2238     asection *srelgot;
2239     asection *splt;
2240     asection *srelplt;
2241     asection *sdynbss;
2242     asection *srelbss;
2243
2244     /* The (unloaded but important) VxWorks .rela.plt.unloaded section.  */
2245     asection *srelplt2;
2246
2247     /* Data for R_ARM_TLS_LDM32 relocations.  */
2248     union {
2249       bfd_signed_vma refcount;
2250       bfd_vma offset;
2251     } tls_ldm_got;
2252     
2253     /* Small local sym to section mapping cache.  */
2254     struct sym_sec_cache sym_sec;
2255
2256     /* For convenience in allocate_dynrelocs.  */
2257     bfd * obfd;
2258   };
2259
2260 /* Create an entry in an ARM ELF linker hash table.  */
2261
2262 static struct bfd_hash_entry *
2263 elf32_arm_link_hash_newfunc (struct bfd_hash_entry * entry,
2264                              struct bfd_hash_table * table,
2265                              const char * string)
2266 {
2267   struct elf32_arm_link_hash_entry * ret =
2268     (struct elf32_arm_link_hash_entry *) entry;
2269
2270   /* Allocate the structure if it has not already been allocated by a
2271      subclass.  */
2272   if (ret == (struct elf32_arm_link_hash_entry *) NULL)
2273     ret = bfd_hash_allocate (table, sizeof (struct elf32_arm_link_hash_entry));
2274   if (ret == NULL)
2275     return (struct bfd_hash_entry *) ret;
2276
2277   /* Call the allocation method of the superclass.  */
2278   ret = ((struct elf32_arm_link_hash_entry *)
2279          _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
2280                                      table, string));
2281   if (ret != NULL)
2282     {
2283       ret->relocs_copied = NULL;
2284       ret->tls_type = GOT_UNKNOWN;
2285       ret->plt_thumb_refcount = 0;
2286       ret->plt_got_offset = -1;
2287       ret->export_glue = NULL;
2288     }
2289
2290   return (struct bfd_hash_entry *) ret;
2291 }
2292
2293 /* Return true if NAME is the name of the relocation section associated
2294    with S.  */
2295
2296 static bfd_boolean
2297 reloc_section_p (struct elf32_arm_link_hash_table *htab,
2298                  const char *name, asection *s)
2299 {
2300   if (htab->use_rel)
2301     return CONST_STRNEQ (name, ".rel") && strcmp (s->name, name + 4) == 0;
2302   else
2303     return CONST_STRNEQ (name, ".rela") && strcmp (s->name, name + 5) == 0;
2304 }
2305
2306 /* Create .got, .gotplt, and .rel(a).got sections in DYNOBJ, and set up
2307    shortcuts to them in our hash table.  */
2308
2309 static bfd_boolean
2310 create_got_section (bfd *dynobj, struct bfd_link_info *info)
2311 {
2312   struct elf32_arm_link_hash_table *htab;
2313
2314   htab = elf32_arm_hash_table (info);
2315   /* BPABI objects never have a GOT, or associated sections.  */
2316   if (htab->symbian_p)
2317     return TRUE;
2318
2319   if (! _bfd_elf_create_got_section (dynobj, info))
2320     return FALSE;
2321
2322   htab->sgot = bfd_get_section_by_name (dynobj, ".got");
2323   htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
2324   if (!htab->sgot || !htab->sgotplt)
2325     abort ();
2326
2327   htab->srelgot = bfd_make_section_with_flags (dynobj,
2328                                                RELOC_SECTION (htab, ".got"),
2329                                                (SEC_ALLOC | SEC_LOAD
2330                                                 | SEC_HAS_CONTENTS
2331                                                 | SEC_IN_MEMORY
2332                                                 | SEC_LINKER_CREATED
2333                                                 | SEC_READONLY));
2334   if (htab->srelgot == NULL
2335       || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2))
2336     return FALSE;
2337   return TRUE;
2338 }
2339
2340 /* Create .plt, .rel(a).plt, .got, .got.plt, .rel(a).got, .dynbss, and
2341    .rel(a).bss sections in DYNOBJ, and set up shortcuts to them in our
2342    hash table.  */
2343
2344 static bfd_boolean
2345 elf32_arm_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
2346 {
2347   struct elf32_arm_link_hash_table *htab;
2348
2349   htab = elf32_arm_hash_table (info);
2350   if (!htab->sgot && !create_got_section (dynobj, info))
2351     return FALSE;
2352
2353   if (!_bfd_elf_create_dynamic_sections (dynobj, info))
2354     return FALSE;
2355
2356   htab->splt = bfd_get_section_by_name (dynobj, ".plt");
2357   htab->srelplt = bfd_get_section_by_name (dynobj,
2358                                            RELOC_SECTION (htab, ".plt"));
2359   htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
2360   if (!info->shared)
2361     htab->srelbss = bfd_get_section_by_name (dynobj,
2362                                              RELOC_SECTION (htab, ".bss"));
2363
2364   if (htab->vxworks_p)
2365     {
2366       if (!elf_vxworks_create_dynamic_sections (dynobj, info, &htab->srelplt2))
2367         return FALSE;
2368
2369       if (info->shared)
2370         {
2371           htab->plt_header_size = 0;
2372           htab->plt_entry_size
2373             = 4 * ARRAY_SIZE (elf32_arm_vxworks_shared_plt_entry);
2374         }
2375       else
2376         {
2377           htab->plt_header_size
2378             = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt0_entry);
2379           htab->plt_entry_size
2380             = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt_entry);
2381         }
2382     }
2383
2384   if (!htab->splt 
2385       || !htab->srelplt
2386       || !htab->sdynbss
2387       || (!info->shared && !htab->srelbss))
2388     abort ();
2389
2390   return TRUE;
2391 }
2392
2393 /* Copy the extra info we tack onto an elf_link_hash_entry.  */
2394
2395 static void
2396 elf32_arm_copy_indirect_symbol (struct bfd_link_info *info,
2397                                 struct elf_link_hash_entry *dir,
2398                                 struct elf_link_hash_entry *ind)
2399 {
2400   struct elf32_arm_link_hash_entry *edir, *eind;
2401
2402   edir = (struct elf32_arm_link_hash_entry *) dir;
2403   eind = (struct elf32_arm_link_hash_entry *) ind;
2404
2405   if (eind->relocs_copied != NULL)
2406     {
2407       if (edir->relocs_copied != NULL)
2408         {
2409           struct elf32_arm_relocs_copied **pp;
2410           struct elf32_arm_relocs_copied *p;
2411
2412           /* Add reloc counts against the indirect sym to the direct sym
2413              list.  Merge any entries against the same section.  */
2414           for (pp = &eind->relocs_copied; (p = *pp) != NULL; )
2415             {
2416               struct elf32_arm_relocs_copied *q;
2417
2418               for (q = edir->relocs_copied; q != NULL; q = q->next)
2419                 if (q->section == p->section)
2420                   {
2421                     q->pc_count += p->pc_count;
2422                     q->count += p->count;
2423                     *pp = p->next;
2424                     break;
2425                   }
2426               if (q == NULL)
2427                 pp = &p->next;
2428             }
2429           *pp = edir->relocs_copied;
2430         }
2431
2432       edir->relocs_copied = eind->relocs_copied;
2433       eind->relocs_copied = NULL;
2434     }
2435
2436   if (ind->root.type == bfd_link_hash_indirect)
2437     {
2438       /* Copy over PLT info.  */
2439       edir->plt_thumb_refcount += eind->plt_thumb_refcount;
2440       eind->plt_thumb_refcount = 0;
2441
2442       if (dir->got.refcount <= 0)
2443         {
2444           edir->tls_type = eind->tls_type;
2445           eind->tls_type = GOT_UNKNOWN;
2446         }
2447     }
2448
2449   _bfd_elf_link_hash_copy_indirect (info, dir, ind);
2450 }
2451
2452 /* Create an ARM elf linker hash table.  */
2453
2454 static struct bfd_link_hash_table *
2455 elf32_arm_link_hash_table_create (bfd *abfd)
2456 {
2457   struct elf32_arm_link_hash_table *ret;
2458   bfd_size_type amt = sizeof (struct elf32_arm_link_hash_table);
2459
2460   ret = bfd_malloc (amt);
2461   if (ret == NULL)
2462     return NULL;
2463
2464   if (!_bfd_elf_link_hash_table_init (& ret->root, abfd,
2465                                       elf32_arm_link_hash_newfunc,
2466                                       sizeof (struct elf32_arm_link_hash_entry)))
2467     {
2468       free (ret);
2469       return NULL;
2470     }
2471
2472   ret->sgot = NULL;
2473   ret->sgotplt = NULL;
2474   ret->srelgot = NULL;
2475   ret->splt = NULL;
2476   ret->srelplt = NULL;
2477   ret->sdynbss = NULL;
2478   ret->srelbss = NULL;
2479   ret->srelplt2 = NULL;
2480   ret->thumb_glue_size = 0;
2481   ret->arm_glue_size = 0;
2482   ret->vfp11_fix = BFD_ARM_VFP11_FIX_NONE;
2483   ret->vfp11_erratum_glue_size = 0;
2484   ret->num_vfp11_fixes = 0;
2485   ret->bfd_of_glue_owner = NULL;
2486   ret->byteswap_code = 0;
2487   ret->target1_is_rel = 0;
2488   ret->target2_reloc = R_ARM_NONE;
2489 #ifdef FOUR_WORD_PLT
2490   ret->plt_header_size = 16;
2491   ret->plt_entry_size = 16;
2492 #else
2493   ret->plt_header_size = 20;
2494   ret->plt_entry_size = 12;
2495 #endif
2496   ret->fix_v4bx = 0;
2497   ret->use_blx = 0;
2498   ret->vxworks_p = 0;
2499   ret->symbian_p = 0;
2500   ret->use_rel = 1;
2501   ret->sym_sec.abfd = NULL;
2502   ret->obfd = abfd;
2503   ret->tls_ldm_got.refcount = 0;
2504
2505   return &ret->root.root;
2506 }
2507
2508 /* Locate the Thumb encoded calling stub for NAME.  */
2509
2510 static struct elf_link_hash_entry *
2511 find_thumb_glue (struct bfd_link_info *link_info,
2512                  const char *name,
2513                  char **error_message)
2514 {
2515   char *tmp_name;
2516   struct elf_link_hash_entry *hash;
2517   struct elf32_arm_link_hash_table *hash_table;
2518
2519   /* We need a pointer to the armelf specific hash table.  */
2520   hash_table = elf32_arm_hash_table (link_info);
2521
2522   tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
2523                          + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1);
2524
2525   BFD_ASSERT (tmp_name);
2526
2527   sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
2528
2529   hash = elf_link_hash_lookup
2530     (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
2531
2532   if (hash == NULL)
2533     asprintf (error_message, _("unable to find THUMB glue '%s' for '%s'"),
2534               tmp_name, name);
2535
2536   free (tmp_name);
2537
2538   return hash;
2539 }
2540
2541 /* Locate the ARM encoded calling stub for NAME.  */
2542
2543 static struct elf_link_hash_entry *
2544 find_arm_glue (struct bfd_link_info *link_info,
2545                const char *name,
2546                char **error_message)
2547 {
2548   char *tmp_name;
2549   struct elf_link_hash_entry *myh;
2550   struct elf32_arm_link_hash_table *hash_table;
2551
2552   /* We need a pointer to the elfarm specific hash table.  */
2553   hash_table = elf32_arm_hash_table (link_info);
2554
2555   tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
2556                          + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1);
2557
2558   BFD_ASSERT (tmp_name);
2559
2560   sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
2561
2562   myh = elf_link_hash_lookup
2563     (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
2564
2565   if (myh == NULL)
2566     asprintf (error_message, _("unable to find ARM glue '%s' for '%s'"),
2567               tmp_name, name);
2568
2569   free (tmp_name);
2570
2571   return myh;
2572 }
2573
2574 /* ARM->Thumb glue (static images):
2575
2576    .arm
2577    __func_from_arm:
2578    ldr r12, __func_addr
2579    bx  r12
2580    __func_addr:
2581    .word func    @ behave as if you saw a ARM_32 reloc.  
2582
2583    (v5t static images)
2584    .arm
2585    __func_from_arm:
2586    ldr pc, __func_addr
2587    __func_addr:
2588    .word func    @ behave as if you saw a ARM_32 reloc.  
2589
2590    (relocatable images)
2591    .arm
2592    __func_from_arm:
2593    ldr r12, __func_offset
2594    add r12, r12, pc
2595    bx  r12
2596    __func_offset:
2597    .word func - .
2598    */
2599
2600 #define ARM2THUMB_STATIC_GLUE_SIZE 12
2601 static const insn32 a2t1_ldr_insn = 0xe59fc000;
2602 static const insn32 a2t2_bx_r12_insn = 0xe12fff1c;
2603 static const insn32 a2t3_func_addr_insn = 0x00000001;
2604
2605 #define ARM2THUMB_V5_STATIC_GLUE_SIZE 8
2606 static const insn32 a2t1v5_ldr_insn = 0xe51ff004;
2607 static const insn32 a2t2v5_func_addr_insn = 0x00000001;
2608
2609 #define ARM2THUMB_PIC_GLUE_SIZE 16
2610 static const insn32 a2t1p_ldr_insn = 0xe59fc004;
2611 static const insn32 a2t2p_add_pc_insn = 0xe08cc00f;
2612 static const insn32 a2t3p_bx_r12_insn = 0xe12fff1c;
2613
2614 /* Thumb->ARM:                          Thumb->(non-interworking aware) ARM
2615
2616    .thumb                               .thumb
2617    .align 2                             .align 2
2618    __func_from_thumb:              __func_from_thumb:
2619    bx pc                                push {r6, lr}
2620    nop                                  ldr  r6, __func_addr
2621    .arm                                         mov  lr, pc
2622    __func_change_to_arm:                        bx   r6
2623    b func                       .arm
2624    __func_back_to_thumb:
2625    ldmia r13! {r6, lr}
2626    bx    lr
2627    __func_addr:
2628    .word        func  */
2629
2630 #define THUMB2ARM_GLUE_SIZE 8
2631 static const insn16 t2a1_bx_pc_insn = 0x4778;
2632 static const insn16 t2a2_noop_insn = 0x46c0;
2633 static const insn32 t2a3_b_insn = 0xea000000;
2634
2635 #define VFP11_ERRATUM_VENEER_SIZE 8
2636
2637 #ifndef ELFARM_NABI_C_INCLUDED
2638 bfd_boolean
2639 bfd_elf32_arm_allocate_interworking_sections (struct bfd_link_info * info)
2640 {
2641   asection * s;
2642   bfd_byte * foo;
2643   struct elf32_arm_link_hash_table * globals;
2644
2645   globals = elf32_arm_hash_table (info);
2646
2647   BFD_ASSERT (globals != NULL);
2648
2649   if (globals->arm_glue_size != 0)
2650     {
2651       BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2652
2653       s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
2654                                    ARM2THUMB_GLUE_SECTION_NAME);
2655
2656       BFD_ASSERT (s != NULL);
2657
2658       foo = bfd_alloc (globals->bfd_of_glue_owner, globals->arm_glue_size);
2659
2660       BFD_ASSERT (s->size == globals->arm_glue_size);
2661       s->contents = foo;
2662     }
2663
2664   if (globals->thumb_glue_size != 0)
2665     {
2666       BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2667
2668       s = bfd_get_section_by_name
2669         (globals->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME);
2670
2671       BFD_ASSERT (s != NULL);
2672
2673       foo = bfd_alloc (globals->bfd_of_glue_owner, globals->thumb_glue_size);
2674
2675       BFD_ASSERT (s->size == globals->thumb_glue_size);
2676       s->contents = foo;
2677     }
2678   
2679   if (globals->vfp11_erratum_glue_size != 0)
2680     {
2681       BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2682       
2683       s = bfd_get_section_by_name
2684         (globals->bfd_of_glue_owner, VFP11_ERRATUM_VENEER_SECTION_NAME);
2685       
2686       BFD_ASSERT (s != NULL);
2687       
2688       foo = bfd_alloc (globals->bfd_of_glue_owner,
2689                        globals->vfp11_erratum_glue_size);
2690       
2691       BFD_ASSERT (s->size == globals->vfp11_erratum_glue_size);
2692       s->contents = foo;
2693     }
2694
2695   return TRUE;
2696 }
2697
2698 /* Allocate space and symbols for calling a Thumb function from Arm mode.
2699    returns the symbol identifying teh stub.  */
2700 static struct elf_link_hash_entry *
2701 record_arm_to_thumb_glue (struct bfd_link_info * link_info,
2702                           struct elf_link_hash_entry * h)
2703 {
2704   const char * name = h->root.root.string;
2705   asection * s;
2706   char * tmp_name;
2707   struct elf_link_hash_entry * myh;
2708   struct bfd_link_hash_entry * bh;
2709   struct elf32_arm_link_hash_table * globals;
2710   bfd_vma val;
2711   bfd_size_type size;
2712
2713   globals = elf32_arm_hash_table (link_info);
2714
2715   BFD_ASSERT (globals != NULL);
2716   BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2717
2718   s = bfd_get_section_by_name
2719     (globals->bfd_of_glue_owner, ARM2THUMB_GLUE_SECTION_NAME);
2720
2721   BFD_ASSERT (s != NULL);
2722
2723   tmp_name = bfd_malloc ((bfd_size_type) strlen (name) + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1);
2724
2725   BFD_ASSERT (tmp_name);
2726
2727   sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
2728
2729   myh = elf_link_hash_lookup
2730     (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
2731
2732   if (myh != NULL)
2733     {
2734       /* We've already seen this guy.  */
2735       free (tmp_name);
2736       return myh;
2737     }
2738
2739   /* The only trick here is using hash_table->arm_glue_size as the value.
2740      Even though the section isn't allocated yet, this is where we will be
2741      putting it.  */
2742   bh = NULL;
2743   val = globals->arm_glue_size + 1;
2744   _bfd_generic_link_add_one_symbol (link_info, globals->bfd_of_glue_owner,
2745                                     tmp_name, BSF_GLOBAL, s, val,
2746                                     NULL, TRUE, FALSE, &bh);
2747
2748   myh = (struct elf_link_hash_entry *) bh;
2749   myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
2750   myh->forced_local = 1;
2751
2752   free (tmp_name);
2753
2754   if (link_info->shared || globals->root.is_relocatable_executable
2755       || globals->pic_veneer)
2756     size = ARM2THUMB_PIC_GLUE_SIZE;
2757   else if (globals->use_blx)
2758     size = ARM2THUMB_V5_STATIC_GLUE_SIZE;
2759   else
2760     size = ARM2THUMB_STATIC_GLUE_SIZE;
2761
2762   s->size += size;
2763   globals->arm_glue_size += size;
2764
2765   return myh;
2766 }
2767
2768 static void
2769 record_thumb_to_arm_glue (struct bfd_link_info *link_info,
2770                           struct elf_link_hash_entry *h)
2771 {
2772   const char *name = h->root.root.string;
2773   asection *s;
2774   char *tmp_name;
2775   struct elf_link_hash_entry *myh;
2776   struct bfd_link_hash_entry *bh;
2777   struct elf32_arm_link_hash_table *hash_table;
2778   bfd_vma val;
2779
2780   hash_table = elf32_arm_hash_table (link_info);
2781
2782   BFD_ASSERT (hash_table != NULL);
2783   BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL);
2784
2785   s = bfd_get_section_by_name
2786     (hash_table->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME);
2787
2788   BFD_ASSERT (s != NULL);
2789
2790   tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
2791                          + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1);
2792
2793   BFD_ASSERT (tmp_name);
2794
2795   sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
2796
2797   myh = elf_link_hash_lookup
2798     (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
2799
2800   if (myh != NULL)
2801     {
2802       /* We've already seen this guy.  */
2803       free (tmp_name);
2804       return;
2805     }
2806
2807   bh = NULL;
2808   val = hash_table->thumb_glue_size + 1;
2809   _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
2810                                     tmp_name, BSF_GLOBAL, s, val,
2811                                     NULL, TRUE, FALSE, &bh);
2812
2813   /* If we mark it 'Thumb', the disassembler will do a better job.  */
2814   myh = (struct elf_link_hash_entry *) bh;
2815   myh->type = ELF_ST_INFO (STB_LOCAL, STT_ARM_TFUNC);
2816   myh->forced_local = 1;
2817
2818   free (tmp_name);
2819
2820 #define CHANGE_TO_ARM "__%s_change_to_arm"
2821 #define BACK_FROM_ARM "__%s_back_from_arm"
2822
2823   /* Allocate another symbol to mark where we switch to Arm mode.  */
2824   tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
2825                          + strlen (CHANGE_TO_ARM) + 1);
2826
2827   BFD_ASSERT (tmp_name);
2828
2829   sprintf (tmp_name, CHANGE_TO_ARM, name);
2830
2831   bh = NULL;
2832   val = hash_table->thumb_glue_size + 4,
2833   _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
2834                                     tmp_name, BSF_LOCAL, s, val,
2835                                     NULL, TRUE, FALSE, &bh);
2836
2837   free (tmp_name);
2838
2839   s->size += THUMB2ARM_GLUE_SIZE;
2840   hash_table->thumb_glue_size += THUMB2ARM_GLUE_SIZE;
2841
2842   return;
2843 }
2844
2845
2846 /* Add an entry to the code/data map for section SEC.  */
2847
2848 static void
2849 elf32_arm_section_map_add (asection *sec, char type, bfd_vma vma)
2850 {
2851   struct _arm_elf_section_data *sec_data = elf32_arm_section_data (sec);
2852   unsigned int newidx;
2853   
2854   if (sec_data->map == NULL)
2855     {
2856       sec_data->map = bfd_malloc (sizeof (elf32_arm_section_map));
2857       sec_data->mapcount = 0;
2858       sec_data->mapsize = 1;
2859     }
2860   
2861   newidx = sec_data->mapcount++;
2862   
2863   if (sec_data->mapcount > sec_data->mapsize)
2864     {
2865       sec_data->mapsize *= 2;
2866       sec_data->map = bfd_realloc (sec_data->map, sec_data->mapsize
2867                                      * sizeof (elf32_arm_section_map));
2868     }
2869   
2870   sec_data->map[newidx].vma = vma;
2871   sec_data->map[newidx].type = type;
2872 }
2873
2874
2875 /* Record information about a VFP11 denorm-erratum veneer.  Only ARM-mode
2876    veneers are handled for now.  */
2877
2878 static bfd_vma
2879 record_vfp11_erratum_veneer (struct bfd_link_info *link_info,
2880                              elf32_vfp11_erratum_list *branch,
2881                              bfd *branch_bfd,
2882                              asection *branch_sec,
2883                              unsigned int offset)
2884 {
2885   asection *s;
2886   struct elf32_arm_link_hash_table *hash_table;
2887   char *tmp_name;
2888   struct elf_link_hash_entry *myh;
2889   struct bfd_link_hash_entry *bh;
2890   bfd_vma val;
2891   struct _arm_elf_section_data *sec_data;
2892   int errcount;
2893   elf32_vfp11_erratum_list *newerr;
2894   
2895   hash_table = elf32_arm_hash_table (link_info);
2896   
2897   BFD_ASSERT (hash_table != NULL);
2898   BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL);
2899   
2900   s = bfd_get_section_by_name
2901     (hash_table->bfd_of_glue_owner, VFP11_ERRATUM_VENEER_SECTION_NAME);
2902   
2903   sec_data = elf32_arm_section_data (s);
2904   
2905   BFD_ASSERT (s != NULL);
2906   
2907   tmp_name = bfd_malloc ((bfd_size_type) strlen
2908                          (VFP11_ERRATUM_VENEER_ENTRY_NAME) + 10);
2909   
2910   BFD_ASSERT (tmp_name);
2911   
2912   sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME,
2913            hash_table->num_vfp11_fixes);
2914   
2915   myh = elf_link_hash_lookup
2916     (&(hash_table)->root, tmp_name, FALSE, FALSE, FALSE);
2917   
2918   BFD_ASSERT (myh == NULL);
2919   
2920   bh = NULL;
2921   val = hash_table->vfp11_erratum_glue_size;
2922   _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
2923                                     tmp_name, BSF_FUNCTION | BSF_LOCAL, s, val,
2924                                     NULL, TRUE, FALSE, &bh);
2925
2926   myh = (struct elf_link_hash_entry *) bh;
2927   myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
2928   myh->forced_local = 1;
2929
2930   /* Link veneer back to calling location.  */
2931   errcount = ++(sec_data->erratumcount);
2932   newerr = bfd_zmalloc (sizeof (elf32_vfp11_erratum_list));
2933   
2934   newerr->type = VFP11_ERRATUM_ARM_VENEER;
2935   newerr->vma = -1;
2936   newerr->u.v.branch = branch;
2937   newerr->u.v.id = hash_table->num_vfp11_fixes;
2938   branch->u.b.veneer = newerr;
2939
2940   newerr->next = sec_data->erratumlist;
2941   sec_data->erratumlist = newerr;
2942
2943   /* A symbol for the return from the veneer.  */
2944   sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME "_r",
2945            hash_table->num_vfp11_fixes);
2946
2947   myh = elf_link_hash_lookup
2948     (&(hash_table)->root, tmp_name, FALSE, FALSE, FALSE);
2949   
2950   if (myh != NULL)
2951     abort ();
2952
2953   bh = NULL;
2954   val = offset + 4;
2955   _bfd_generic_link_add_one_symbol (link_info, branch_bfd, tmp_name, BSF_LOCAL,
2956                                     branch_sec, val, NULL, TRUE, FALSE, &bh);
2957   
2958   myh = (struct elf_link_hash_entry *) bh;
2959   myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
2960   myh->forced_local = 1;
2961
2962   free (tmp_name);
2963   
2964   /* Generate a mapping symbol for the veneer section, and explicitly add an
2965      entry for that symbol to the code/data map for the section.  */
2966   if (hash_table->vfp11_erratum_glue_size == 0)
2967     {
2968       bh = NULL;
2969       /* FIXME: Creates an ARM symbol.  Thumb mode will need attention if it
2970          ever requires this erratum fix.  */
2971       _bfd_generic_link_add_one_symbol (link_info,
2972                                         hash_table->bfd_of_glue_owner, "$a",
2973                                         BSF_LOCAL, s, 0, NULL,
2974                                         TRUE, FALSE, &bh);
2975
2976       myh = (struct elf_link_hash_entry *) bh;
2977       myh->type = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
2978       myh->forced_local = 1;
2979       
2980       /* The elf32_arm_init_maps function only cares about symbols from input
2981          BFDs.  We must make a note of this generated mapping symbol
2982          ourselves so that code byteswapping works properly in
2983          elf32_arm_write_section.  */
2984       elf32_arm_section_map_add (s, 'a', 0);
2985     }
2986   
2987   s->size += VFP11_ERRATUM_VENEER_SIZE;
2988   hash_table->vfp11_erratum_glue_size += VFP11_ERRATUM_VENEER_SIZE;
2989   hash_table->num_vfp11_fixes++;
2990   
2991   /* The offset of the veneer.  */
2992   return val;
2993 }
2994
2995 /* Add the glue sections to ABFD.  This function is called from the
2996    linker scripts in ld/emultempl/{armelf}.em.  */
2997
2998 bfd_boolean
2999 bfd_elf32_arm_add_glue_sections_to_bfd (bfd *abfd,
3000                                         struct bfd_link_info *info)
3001 {
3002   flagword flags;
3003   asection *sec;
3004
3005   /* If we are only performing a partial
3006      link do not bother adding the glue.  */
3007   if (info->relocatable)
3008     return TRUE;
3009
3010   sec = bfd_get_section_by_name (abfd, ARM2THUMB_GLUE_SECTION_NAME);
3011
3012   if (sec == NULL)
3013     {
3014       /* Note: we do not include the flag SEC_LINKER_CREATED, as this
3015          will prevent elf_link_input_bfd() from processing the contents
3016          of this section.  */
3017       flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
3018                | SEC_CODE | SEC_READONLY);
3019
3020       sec = bfd_make_section_with_flags (abfd,
3021                                          ARM2THUMB_GLUE_SECTION_NAME,
3022                                          flags);
3023
3024       if (sec == NULL
3025           || !bfd_set_section_alignment (abfd, sec, 2))
3026         return FALSE;
3027
3028       /* Set the gc mark to prevent the section from being removed by garbage
3029          collection, despite the fact that no relocs refer to this section.  */
3030       sec->gc_mark = 1;
3031     }
3032
3033   sec = bfd_get_section_by_name (abfd, THUMB2ARM_GLUE_SECTION_NAME);
3034
3035   if (sec == NULL)
3036     {
3037       flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
3038                | SEC_CODE | SEC_READONLY);
3039
3040       sec = bfd_make_section_with_flags (abfd,
3041                                          THUMB2ARM_GLUE_SECTION_NAME,
3042                                          flags);
3043
3044       if (sec == NULL
3045           || !bfd_set_section_alignment (abfd, sec, 2))
3046         return FALSE;
3047
3048       sec->gc_mark = 1;
3049     }
3050
3051   sec = bfd_get_section_by_name (abfd, VFP11_ERRATUM_VENEER_SECTION_NAME);
3052
3053   if (sec == NULL)
3054     {
3055       flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
3056                | SEC_CODE | SEC_READONLY);
3057
3058       sec = bfd_make_section_with_flags (abfd,
3059                                          VFP11_ERRATUM_VENEER_SECTION_NAME,
3060                                          flags);
3061
3062       if (sec == NULL
3063           || !bfd_set_section_alignment (abfd, sec, 2))
3064         return FALSE;
3065
3066       sec->gc_mark = 1;
3067     }
3068
3069   return TRUE;
3070 }
3071
3072 /* Select a BFD to be used to hold the sections used by the glue code.
3073    This function is called from the linker scripts in ld/emultempl/
3074    {armelf/pe}.em  */
3075
3076 bfd_boolean
3077 bfd_elf32_arm_get_bfd_for_interworking (bfd *abfd, struct bfd_link_info *info)
3078 {
3079   struct elf32_arm_link_hash_table *globals;
3080
3081   /* If we are only performing a partial link
3082      do not bother getting a bfd to hold the glue.  */
3083   if (info->relocatable)
3084     return TRUE;
3085
3086   /* Make sure we don't attach the glue sections to a dynamic object.  */
3087   BFD_ASSERT (!(abfd->flags & DYNAMIC));
3088
3089   globals = elf32_arm_hash_table (info);
3090
3091   BFD_ASSERT (globals != NULL);
3092
3093   if (globals->bfd_of_glue_owner != NULL)
3094     return TRUE;
3095
3096   /* Save the bfd for later use.  */
3097   globals->bfd_of_glue_owner = abfd;
3098
3099   return TRUE;
3100 }
3101
3102 static void check_use_blx(struct elf32_arm_link_hash_table *globals)
3103 {
3104   if (bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC,
3105                                 Tag_CPU_arch) > 2)
3106     globals->use_blx = 1;
3107 }
3108
3109 bfd_boolean
3110 bfd_elf32_arm_process_before_allocation (bfd *abfd,
3111                                          struct bfd_link_info *link_info)
3112 {
3113   Elf_Internal_Shdr *symtab_hdr;
3114   Elf_Internal_Rela *internal_relocs = NULL;
3115   Elf_Internal_Rela *irel, *irelend;
3116   bfd_byte *contents = NULL;
3117
3118   asection *sec;
3119   struct elf32_arm_link_hash_table *globals;
3120
3121   /* If we are only performing a partial link do not bother
3122      to construct any glue.  */
3123   if (link_info->relocatable)
3124     return TRUE;
3125
3126   /* Here we have a bfd that is to be included on the link.  We have a hook
3127      to do reloc rummaging, before section sizes are nailed down.  */
3128   globals = elf32_arm_hash_table (link_info);
3129   check_use_blx (globals);
3130
3131   BFD_ASSERT (globals != NULL);
3132   BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
3133
3134   if (globals->byteswap_code && !bfd_big_endian (abfd))
3135     {
3136       _bfd_error_handler (_("%B: BE8 images only valid in big-endian mode."),
3137                           abfd);
3138       return FALSE;
3139     }
3140
3141   /* Rummage around all the relocs and map the glue vectors.  */
3142   sec = abfd->sections;
3143
3144   if (sec == NULL)
3145     return TRUE;
3146
3147   for (; sec != NULL; sec = sec->next)
3148     {
3149       if (sec->reloc_count == 0)
3150         continue;
3151
3152       if ((sec->flags & SEC_EXCLUDE) != 0)
3153         continue;
3154
3155       symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
3156
3157       /* Load the relocs.  */
3158       internal_relocs
3159         = _bfd_elf_link_read_relocs (abfd, sec, (void *) NULL,
3160                                      (Elf_Internal_Rela *) NULL, FALSE);
3161
3162       if (internal_relocs == NULL)
3163         goto error_return;
3164
3165       irelend = internal_relocs + sec->reloc_count;
3166       for (irel = internal_relocs; irel < irelend; irel++)
3167         {
3168           long r_type;
3169           unsigned long r_index;
3170
3171           struct elf_link_hash_entry *h;
3172
3173           r_type = ELF32_R_TYPE (irel->r_info);
3174           r_index = ELF32_R_SYM (irel->r_info);
3175
3176           /* These are the only relocation types we care about.  */
3177           if (   r_type != R_ARM_PC24
3178               && r_type != R_ARM_PLT32
3179               && r_type != R_ARM_CALL
3180               && r_type != R_ARM_JUMP24
3181               && r_type != R_ARM_THM_CALL)
3182             continue;
3183
3184           /* Get the section contents if we haven't done so already.  */
3185           if (contents == NULL)
3186             {
3187               /* Get cached copy if it exists.  */
3188               if (elf_section_data (sec)->this_hdr.contents != NULL)
3189                 contents = elf_section_data (sec)->this_hdr.contents;
3190               else
3191                 {
3192                   /* Go get them off disk.  */
3193                   if (! bfd_malloc_and_get_section (abfd, sec, &contents))
3194                     goto error_return;
3195                 }
3196             }
3197
3198           /* If the relocation is not against a symbol it cannot concern us.  */
3199           h = NULL;
3200
3201           /* We don't care about local symbols.  */
3202           if (r_index < symtab_hdr->sh_info)
3203             continue;
3204
3205           /* This is an external symbol.  */
3206           r_index -= symtab_hdr->sh_info;
3207           h = (struct elf_link_hash_entry *)
3208             elf_sym_hashes (abfd)[r_index];
3209
3210           /* If the relocation is against a static symbol it must be within
3211              the current section and so cannot be a cross ARM/Thumb relocation.  */
3212           if (h == NULL)
3213             continue;
3214
3215           /* If the call will go through a PLT entry then we do not need
3216              glue.  */
3217           if (globals->splt != NULL && h->plt.offset != (bfd_vma) -1)
3218             continue;
3219
3220           switch (r_type)
3221             {
3222             case R_ARM_PC24:
3223             case R_ARM_PLT32:
3224             case R_ARM_CALL:
3225             case R_ARM_JUMP24:
3226               /* This one is a call from arm code.  We need to look up
3227                  the target of the call.  If it is a thumb target, we
3228                  insert glue.  */
3229               if (ELF_ST_TYPE(h->type) == STT_ARM_TFUNC
3230                   && !(r_type == R_ARM_CALL && globals->use_blx))
3231                 record_arm_to_thumb_glue (link_info, h);
3232               break;
3233
3234             case R_ARM_THM_CALL:
3235               /* This one is a call from thumb code.  We look
3236                  up the target of the call.  If it is not a thumb
3237                  target, we insert glue.  */
3238               if (ELF_ST_TYPE (h->type) != STT_ARM_TFUNC && !globals->use_blx
3239                   && h->root.type != bfd_link_hash_undefweak)
3240                 record_thumb_to_arm_glue (link_info, h);
3241               break;
3242
3243             default:
3244               abort ();
3245             }
3246         }
3247
3248       if (contents != NULL
3249           && elf_section_data (sec)->this_hdr.contents != contents)
3250         free (contents);
3251       contents = NULL;
3252
3253       if (internal_relocs != NULL
3254           && elf_section_data (sec)->relocs != internal_relocs)
3255         free (internal_relocs);
3256       internal_relocs = NULL;
3257     }
3258
3259   return TRUE;
3260
3261 error_return:
3262   if (contents != NULL
3263       && elf_section_data (sec)->this_hdr.contents != contents)
3264     free (contents);
3265   if (internal_relocs != NULL
3266       && elf_section_data (sec)->relocs != internal_relocs)
3267     free (internal_relocs);
3268
3269   return FALSE;
3270 }
3271 #endif
3272
3273
3274 /* Initialise maps of ARM/Thumb/data for input BFDs.  */
3275
3276 void
3277 bfd_elf32_arm_init_maps (bfd *abfd)
3278 {
3279   Elf_Internal_Sym *isymbuf;
3280   Elf_Internal_Shdr *hdr;
3281   unsigned int i, localsyms;
3282
3283   if (bfd_get_flavour (abfd) != bfd_target_elf_flavour || elf_tdata (abfd) == NULL)
3284     return;
3285
3286   if ((abfd->flags & DYNAMIC) != 0)
3287     return;
3288
3289   hdr = &elf_tdata (abfd)->symtab_hdr;
3290   localsyms = hdr->sh_info;
3291
3292   /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
3293      should contain the number of local symbols, which should come before any
3294      global symbols.  Mapping symbols are always local.  */
3295   isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL,
3296                                   NULL);
3297
3298   /* No internal symbols read?  Skip this BFD.  */
3299   if (isymbuf == NULL)
3300     return;
3301
3302   for (i = 0; i < localsyms; i++)
3303     {
3304       Elf_Internal_Sym *isym = &isymbuf[i];
3305       asection *sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
3306       const char *name;
3307       
3308       if (sec != NULL
3309           && ELF_ST_BIND (isym->st_info) == STB_LOCAL)
3310         {
3311           name = bfd_elf_string_from_elf_section (abfd,
3312             hdr->sh_link, isym->st_name);
3313           
3314           if (bfd_is_arm_special_symbol_name (name,
3315                                               BFD_ARM_SPECIAL_SYM_TYPE_MAP))
3316             elf32_arm_section_map_add (sec, name[1], isym->st_value);
3317         }
3318     }
3319 }
3320
3321
3322 void
3323 bfd_elf32_arm_set_vfp11_fix (bfd *obfd, struct bfd_link_info *link_info)
3324 {
3325   struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
3326   obj_attribute *out_attr = elf_known_obj_attributes_proc (obfd);
3327   
3328   /* We assume that ARMv7+ does not need the VFP11 denorm erratum fix.  */
3329   if (out_attr[Tag_CPU_arch].i >= TAG_CPU_ARCH_V7)
3330     {
3331       switch (globals->vfp11_fix)
3332         {
3333         case BFD_ARM_VFP11_FIX_DEFAULT:
3334         case BFD_ARM_VFP11_FIX_NONE:
3335           globals->vfp11_fix = BFD_ARM_VFP11_FIX_NONE;
3336           break;
3337         
3338         default:
3339           /* Give a warning, but do as the user requests anyway.  */
3340           (*_bfd_error_handler) (_("%B: warning: selected VFP11 erratum "
3341             "workaround is not necessary for target architecture"), obfd);
3342         }
3343     }
3344   else if (globals->vfp11_fix == BFD_ARM_VFP11_FIX_DEFAULT)
3345     /* For earlier architectures, we might need the workaround, but do not
3346        enable it by default.  If users is running with broken hardware, they
3347        must enable the erratum fix explicitly.  */
3348     globals->vfp11_fix = BFD_ARM_VFP11_FIX_NONE;
3349 }
3350
3351
3352 enum bfd_arm_vfp11_pipe {
3353   VFP11_FMAC,
3354   VFP11_LS,
3355   VFP11_DS,
3356   VFP11_BAD
3357 };
3358
3359 /* Return a VFP register number.  This is encoded as RX:X for single-precision
3360    registers, or X:RX for double-precision registers, where RX is the group of
3361    four bits in the instruction encoding and X is the single extension bit.
3362    RX and X fields are specified using their lowest (starting) bit.  The return
3363    value is:
3364
3365      0...31: single-precision registers s0...s31
3366      32...63: double-precision registers d0...d31.
3367   
3368    Although X should be zero for VFP11 (encoding d0...d15 only), we might
3369    encounter VFP3 instructions, so we allow the full range for DP registers.  */
3370    
3371 static unsigned int
3372 bfd_arm_vfp11_regno (unsigned int insn, bfd_boolean is_double, unsigned int rx,
3373                      unsigned int x)
3374 {
3375   if (is_double)
3376     return (((insn >> rx) & 0xf) | (((insn >> x) & 1) << 4)) + 32;
3377   else
3378     return (((insn >> rx) & 0xf) << 1) | ((insn >> x) & 1);
3379 }
3380
3381 /* Set bits in *WMASK according to a register number REG as encoded by
3382    bfd_arm_vfp11_regno().  Ignore d16-d31.  */
3383
3384 static void
3385 bfd_arm_vfp11_write_mask (unsigned int *wmask, unsigned int reg)
3386 {
3387   if (reg < 32)
3388     *wmask |= 1 << reg;
3389   else if (reg < 48)
3390     *wmask |= 3 << ((reg - 32) * 2);
3391 }
3392
3393 /* Return TRUE if WMASK overwrites anything in REGS.  */
3394
3395 static bfd_boolean
3396 bfd_arm_vfp11_antidependency (unsigned int wmask, int *regs, int numregs)
3397 {
3398   int i;
3399   
3400   for (i = 0; i < numregs; i++)
3401     {
3402       unsigned int reg = regs[i];
3403
3404       if (reg < 32 && (wmask & (1 << reg)) != 0)
3405         return TRUE;
3406       
3407       reg -= 32;
3408
3409       if (reg >= 16)
3410         continue;
3411       
3412       if ((wmask & (3 << (reg * 2))) != 0)
3413         return TRUE;
3414     }
3415   
3416   return FALSE;
3417 }
3418
3419 /* In this function, we're interested in two things: finding input registers
3420    for VFP data-processing instructions, and finding the set of registers which
3421    arbitrary VFP instructions may write to.  We use a 32-bit unsigned int to
3422    hold the written set, so FLDM etc. are easy to deal with (we're only
3423    interested in 32 SP registers or 16 dp registers, due to the VFP version
3424    implemented by the chip in question).  DP registers are marked by setting
3425    both SP registers in the write mask).  */
3426
3427 static enum bfd_arm_vfp11_pipe
3428 bfd_arm_vfp11_insn_decode (unsigned int insn, unsigned int *destmask, int *regs,
3429                            int *numregs)
3430 {
3431   enum bfd_arm_vfp11_pipe pipe = VFP11_BAD;
3432   bfd_boolean is_double = ((insn & 0xf00) == 0xb00) ? 1 : 0;
3433
3434   if ((insn & 0x0f000e10) == 0x0e000a00)  /* A data-processing insn.  */
3435     {
3436       unsigned int pqrs;
3437       unsigned int fd = bfd_arm_vfp11_regno (insn, is_double, 12, 22);
3438       unsigned int fm = bfd_arm_vfp11_regno (insn, is_double, 0, 5);
3439
3440       pqrs = ((insn & 0x00800000) >> 20)
3441            | ((insn & 0x00300000) >> 19)
3442            | ((insn & 0x00000040) >> 6);
3443
3444       switch (pqrs)
3445         {
3446         case 0: /* fmac[sd].  */
3447         case 1: /* fnmac[sd].  */
3448         case 2: /* fmsc[sd].  */
3449         case 3: /* fnmsc[sd].  */
3450           pipe = VFP11_FMAC;
3451           bfd_arm_vfp11_write_mask (destmask, fd);
3452           regs[0] = fd;
3453           regs[1] = bfd_arm_vfp11_regno (insn, is_double, 16, 7);  /* Fn.  */
3454           regs[2] = fm;
3455           *numregs = 3;
3456           break;
3457
3458         case 4: /* fmul[sd].  */
3459         case 5: /* fnmul[sd].  */
3460         case 6: /* fadd[sd].  */
3461         case 7: /* fsub[sd].  */
3462           pipe = VFP11_FMAC;
3463           goto vfp_binop;
3464
3465         case 8: /* fdiv[sd].  */
3466           pipe = VFP11_DS;
3467           vfp_binop:
3468           bfd_arm_vfp11_write_mask (destmask, fd);
3469           regs[0] = bfd_arm_vfp11_regno (insn, is_double, 16, 7);   /* Fn.  */
3470           regs[1] = fm;
3471           *numregs = 2;
3472           break;
3473
3474         case 15: /* extended opcode.  */
3475           {
3476             unsigned int extn = ((insn >> 15) & 0x1e)
3477                               | ((insn >> 7) & 1);
3478
3479             switch (extn)
3480               {
3481               case 0: /* fcpy[sd].  */
3482               case 1: /* fabs[sd].  */
3483               case 2: /* fneg[sd].  */
3484               case 8: /* fcmp[sd].  */
3485               case 9: /* fcmpe[sd].  */
3486               case 10: /* fcmpz[sd].  */
3487               case 11: /* fcmpez[sd].  */
3488               case 16: /* fuito[sd].  */
3489               case 17: /* fsito[sd].  */
3490               case 24: /* ftoui[sd].  */
3491               case 25: /* ftouiz[sd].  */
3492               case 26: /* ftosi[sd].  */
3493               case 27: /* ftosiz[sd].  */
3494                 /* These instructions will not bounce due to underflow.  */
3495                 *numregs = 0;
3496                 pipe = VFP11_FMAC;
3497                 break;
3498
3499               case 3: /* fsqrt[sd].  */
3500                 /* fsqrt cannot underflow, but it can (perhaps) overwrite
3501                    registers to cause the erratum in previous instructions.  */
3502                 bfd_arm_vfp11_write_mask (destmask, fd);
3503                 pipe = VFP11_DS;
3504                 break;
3505
3506               case 15: /* fcvt{ds,sd}.  */
3507                 {
3508                   int rnum = 0;
3509
3510                   bfd_arm_vfp11_write_mask (destmask, fd);
3511
3512                   /* Only FCVTSD can underflow.  */
3513                   if ((insn & 0x100) != 0)
3514                     regs[rnum++] = fm;
3515
3516                   *numregs = rnum;
3517
3518                   pipe = VFP11_FMAC;
3519                 }
3520                 break;
3521
3522               default:
3523                 return VFP11_BAD;
3524               }
3525           }
3526           break;
3527
3528         default:
3529           return VFP11_BAD;
3530         }
3531     }
3532   /* Two-register transfer.  */
3533   else if ((insn & 0x0fe00ed0) == 0x0c400a10)
3534     {
3535       unsigned int fm = bfd_arm_vfp11_regno (insn, is_double, 0, 5);
3536       
3537       if ((insn & 0x100000) == 0)
3538         {
3539           if (is_double)
3540             bfd_arm_vfp11_write_mask (destmask, fm);
3541           else
3542             {
3543               bfd_arm_vfp11_write_mask (destmask, fm);
3544               bfd_arm_vfp11_write_mask (destmask, fm + 1);
3545             }
3546         }
3547
3548       pipe = VFP11_LS;
3549     }
3550   else if ((insn & 0x0e100e00) == 0x0c100a00)  /* A load insn.  */
3551     {
3552       int fd = bfd_arm_vfp11_regno (insn, is_double, 12, 22);
3553       unsigned int puw = ((insn >> 21) & 0x1) | (((insn >> 23) & 3) << 1);
3554       
3555       switch (puw)
3556         {
3557         case 0: /* Two-reg transfer.  We should catch these above.  */
3558           abort ();
3559         
3560         case 2: /* fldm[sdx].  */
3561         case 3:
3562         case 5:
3563           {
3564             unsigned int i, offset = insn & 0xff;
3565
3566             if (is_double)
3567               offset >>= 1;
3568
3569             for (i = fd; i < fd + offset; i++)
3570               bfd_arm_vfp11_write_mask (destmask, i);
3571           }
3572           break;
3573         
3574         case 4: /* fld[sd].  */
3575         case 6:
3576           bfd_arm_vfp11_write_mask (destmask, fd);
3577           break;
3578         
3579         default:
3580           return VFP11_BAD;
3581         }
3582
3583       pipe = VFP11_LS;
3584     }
3585   /* Single-register transfer. Note L==0.  */
3586   else if ((insn & 0x0f100e10) == 0x0e000a10)
3587     {
3588       unsigned int opcode = (insn >> 21) & 7;
3589       unsigned int fn = bfd_arm_vfp11_regno (insn, is_double, 16, 7);
3590
3591       switch (opcode)
3592         {
3593         case 0: /* fmsr/fmdlr.  */
3594         case 1: /* fmdhr.  */
3595           /* Mark fmdhr and fmdlr as writing to the whole of the DP
3596              destination register.  I don't know if this is exactly right,
3597              but it is the conservative choice.  */
3598           bfd_arm_vfp11_write_mask (destmask, fn);
3599           break;
3600
3601         case 7: /* fmxr.  */
3602           break;
3603         }
3604
3605       pipe = VFP11_LS;
3606     }
3607
3608   return pipe;
3609 }
3610
3611
3612 static int elf32_arm_compare_mapping (const void * a, const void * b);
3613
3614
3615 /* Look for potentially-troublesome code sequences which might trigger the
3616    VFP11 denormal/antidependency erratum.  See, e.g., the ARM1136 errata sheet
3617    (available from ARM) for details of the erratum.  A short version is
3618    described in ld.texinfo.  */
3619
3620 bfd_boolean
3621 bfd_elf32_arm_vfp11_erratum_scan (bfd *abfd, struct bfd_link_info *link_info)
3622 {
3623   asection *sec;
3624   bfd_byte *contents = NULL;
3625   int state = 0;
3626   int regs[3], numregs = 0;
3627   struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
3628   int use_vector = (globals->vfp11_fix == BFD_ARM_VFP11_FIX_VECTOR);
3629   
3630   /* We use a simple FSM to match troublesome VFP11 instruction sequences.
3631      The states transition as follows:
3632      
3633        0 -> 1 (vector) or 0 -> 2 (scalar)
3634            A VFP FMAC-pipeline instruction has been seen. Fill
3635            regs[0]..regs[numregs-1] with its input operands. Remember this
3636            instruction in 'first_fmac'.
3637
3638        1 -> 2
3639            Any instruction, except for a VFP instruction which overwrites
3640            regs[*].
3641        
3642        1 -> 3 [ -> 0 ]  or
3643        2 -> 3 [ -> 0 ]
3644            A VFP instruction has been seen which overwrites any of regs[*].
3645            We must make a veneer!  Reset state to 0 before examining next
3646            instruction.
3647        
3648        2 -> 0
3649            If we fail to match anything in state 2, reset to state 0 and reset
3650            the instruction pointer to the instruction after 'first_fmac'.
3651
3652      If the VFP11 vector mode is in use, there must be at least two unrelated
3653      instructions between anti-dependent VFP11 instructions to properly avoid
3654      triggering the erratum, hence the use of the extra state 1.
3655   */
3656
3657   /* If we are only performing a partial link do not bother
3658      to construct any glue.  */
3659   if (link_info->relocatable)
3660     return TRUE;
3661
3662   /* We should have chosen a fix type by the time we get here.  */
3663   BFD_ASSERT (globals->vfp11_fix != BFD_ARM_VFP11_FIX_DEFAULT);
3664
3665   if (globals->vfp11_fix == BFD_ARM_VFP11_FIX_NONE)
3666     return TRUE;
3667
3668   /* Skip if this bfd does not correspond to an ELF image.  */
3669   if (bfd_get_flavour (abfd) != bfd_target_elf_flavour)
3670     return TRUE;
3671   
3672   for (sec = abfd->sections; sec != NULL; sec = sec->next)
3673     {
3674       unsigned int i, span, first_fmac = 0, veneer_of_insn = 0;
3675       struct _arm_elf_section_data *sec_data;
3676
3677       /* If we don't have executable progbits, we're not interested in this
3678          section.  Also skip if section is to be excluded.  */
3679       if (elf_section_type (sec) != SHT_PROGBITS
3680           || (elf_section_flags (sec) & SHF_EXECINSTR) == 0
3681           || (sec->flags & SEC_EXCLUDE) != 0
3682           || strcmp (sec->name, VFP11_ERRATUM_VENEER_SECTION_NAME) == 0)
3683         continue;
3684
3685       sec_data = elf32_arm_section_data (sec);
3686       
3687       if (sec_data->mapcount == 0)
3688         continue;
3689       
3690       if (elf_section_data (sec)->this_hdr.contents != NULL)
3691         contents = elf_section_data (sec)->this_hdr.contents;
3692       else if (! bfd_malloc_and_get_section (abfd, sec, &contents))
3693         goto error_return;
3694
3695       qsort (sec_data->map, sec_data->mapcount, sizeof (elf32_arm_section_map),
3696              elf32_arm_compare_mapping);
3697
3698       for (span = 0; span < sec_data->mapcount; span++)
3699         {
3700           unsigned int span_start = sec_data->map[span].vma;
3701           unsigned int span_end = (span == sec_data->mapcount - 1)
3702                                   ? sec->size : sec_data->map[span + 1].vma;
3703           char span_type = sec_data->map[span].type;
3704           
3705           /* FIXME: Only ARM mode is supported at present.  We may need to
3706              support Thumb-2 mode also at some point.  */
3707           if (span_type != 'a')
3708             continue;
3709
3710           for (i = span_start; i < span_end;)
3711             {
3712               unsigned int next_i = i + 4;
3713               unsigned int insn = bfd_big_endian (abfd)
3714                 ? (contents[i] << 24)
3715                   | (contents[i + 1] << 16)
3716                   | (contents[i + 2] << 8)
3717                   | contents[i + 3]
3718                 : (contents[i + 3] << 24)
3719                   | (contents[i + 2] << 16)
3720                   | (contents[i + 1] << 8)
3721                   | contents[i];
3722               unsigned int writemask = 0;
3723               enum bfd_arm_vfp11_pipe pipe;
3724
3725               switch (state)
3726                 {
3727                 case 0:
3728                   pipe = bfd_arm_vfp11_insn_decode (insn, &writemask, regs,
3729                                                     &numregs);
3730                   /* I'm assuming the VFP11 erratum can trigger with denorm
3731                      operands on either the FMAC or the DS pipeline. This might
3732                      lead to slightly overenthusiastic veneer insertion.  */
3733                   if (pipe == VFP11_FMAC || pipe == VFP11_DS)
3734                     {
3735                       state = use_vector ? 1 : 2;
3736                       first_fmac = i;
3737                       veneer_of_insn = insn;
3738                     }
3739                   break;
3740
3741                 case 1:
3742                   {
3743                     int other_regs[3], other_numregs;
3744                     pipe = bfd_arm_vfp11_insn_decode (insn, &writemask,
3745                                                       other_regs,
3746                                                       &other_numregs);
3747                     if (pipe != VFP11_BAD
3748                         && bfd_arm_vfp11_antidependency (writemask, regs,
3749                                                          numregs))
3750                       state = 3;
3751                     else
3752                       state = 2;
3753                   }
3754                   break;
3755
3756                 case 2:
3757                   {
3758                     int other_regs[3], other_numregs;
3759                     pipe = bfd_arm_vfp11_insn_decode (insn, &writemask,
3760                                                       other_regs,
3761                                                       &other_numregs);
3762                     if (pipe != VFP11_BAD
3763                         && bfd_arm_vfp11_antidependency (writemask, regs,
3764                                                          numregs))
3765                       state = 3;
3766                     else
3767                       {
3768                         state = 0;
3769                         next_i = first_fmac + 4;
3770                       }
3771                   }
3772                   break;
3773
3774                 case 3:
3775                   abort ();  /* Should be unreachable.  */
3776                 }
3777
3778               if (state == 3)
3779                 {
3780                   elf32_vfp11_erratum_list *newerr
3781                     = bfd_zmalloc (sizeof (elf32_vfp11_erratum_list));
3782                   int errcount;
3783
3784                   errcount = ++(elf32_arm_section_data (sec)->erratumcount);
3785
3786                   newerr->u.b.vfp_insn = veneer_of_insn;
3787
3788                   switch (span_type)
3789                     {
3790                     case 'a':
3791                       newerr->type = VFP11_ERRATUM_BRANCH_TO_ARM_VENEER;
3792                       break;
3793                     
3794                     default:
3795                       abort ();
3796                     }
3797
3798                   record_vfp11_erratum_veneer (link_info, newerr, abfd, sec,
3799                                                first_fmac);
3800
3801                   newerr->vma = -1;
3802
3803                   newerr->next = sec_data->erratumlist;
3804                   sec_data->erratumlist = newerr;
3805
3806                   state = 0;
3807                 }
3808
3809               i = next_i;
3810             }
3811         }
3812       
3813       if (contents != NULL
3814           && elf_section_data (sec)->this_hdr.contents != contents)
3815         free (contents);
3816       contents = NULL;
3817     }
3818
3819   return TRUE;
3820
3821 error_return:
3822   if (contents != NULL
3823       && elf_section_data (sec)->this_hdr.contents != contents)
3824     free (contents);
3825   
3826   return FALSE;
3827 }
3828
3829 /* Find virtual-memory addresses for VFP11 erratum veneers and return locations
3830    after sections have been laid out, using specially-named symbols.  */
3831
3832 void
3833 bfd_elf32_arm_vfp11_fix_veneer_locations (bfd *abfd,
3834                                           struct bfd_link_info *link_info)
3835 {
3836   asection *sec;
3837   struct elf32_arm_link_hash_table *globals;
3838   char *tmp_name;
3839   
3840   if (link_info->relocatable)
3841     return;
3842
3843   /* Skip if this bfd does not correspond to an ELF image.  */
3844   if (bfd_get_flavour (abfd) != bfd_target_elf_flavour)
3845     return;
3846
3847   globals = elf32_arm_hash_table (link_info);
3848   
3849   tmp_name = bfd_malloc ((bfd_size_type) strlen
3850                            (VFP11_ERRATUM_VENEER_ENTRY_NAME) + 10);
3851
3852   for (sec = abfd->sections; sec != NULL; sec = sec->next)
3853     {
3854       struct _arm_elf_section_data *sec_data = elf32_arm_section_data (sec);
3855       elf32_vfp11_erratum_list *errnode = sec_data->erratumlist;
3856       
3857       for (; errnode != NULL; errnode = errnode->next)
3858         {
3859           struct elf_link_hash_entry *myh;
3860           bfd_vma vma;
3861
3862           switch (errnode->type)
3863             {
3864             case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER:
3865             case VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER:
3866               /* Find veneer symbol.  */
3867               sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME,
3868                        errnode->u.b.veneer->u.v.id);
3869
3870               myh = elf_link_hash_lookup
3871                 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
3872
3873               if (myh == NULL)
3874                 (*_bfd_error_handler) (_("%B: unable to find VFP11 veneer "
3875                                          "`%s'"), abfd, tmp_name);
3876
3877               vma = myh->root.u.def.section->output_section->vma
3878                     + myh->root.u.def.section->output_offset
3879                     + myh->root.u.def.value;
3880
3881               errnode->u.b.veneer->vma = vma;
3882               break;
3883
3884             case VFP11_ERRATUM_ARM_VENEER:
3885             case VFP11_ERRATUM_THUMB_VENEER:
3886               /* Find return location.  */
3887               sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME "_r",
3888                        errnode->u.v.id);
3889
3890               myh = elf_link_hash_lookup
3891                 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
3892
3893               if (myh == NULL)
3894                 (*_bfd_error_handler) (_("%B: unable to find VFP11 veneer "
3895                                          "`%s'"), abfd, tmp_name);
3896
3897               vma = myh->root.u.def.section->output_section->vma
3898                     + myh->root.u.def.section->output_offset
3899                     + myh->root.u.def.value;
3900
3901               errnode->u.v.branch->vma = vma;
3902               break;
3903             
3904             default:
3905               abort ();
3906             }
3907         }
3908     }
3909   
3910   free (tmp_name);
3911 }
3912
3913
3914 /* Set target relocation values needed during linking.  */
3915
3916 void
3917 bfd_elf32_arm_set_target_relocs (struct bfd *output_bfd,
3918                                  struct bfd_link_info *link_info,
3919                                  int target1_is_rel,
3920                                  char * target2_type,
3921                                  int fix_v4bx,
3922                                  int use_blx,
3923                                  bfd_arm_vfp11_fix vfp11_fix,
3924                                  int no_enum_warn, int pic_veneer)
3925 {
3926   struct elf32_arm_link_hash_table *globals;
3927
3928   globals = elf32_arm_hash_table (link_info);
3929
3930   globals->target1_is_rel = target1_is_rel;
3931   if (strcmp (target2_type, "rel") == 0)
3932     globals->target2_reloc = R_ARM_REL32;
3933   else if (strcmp (target2_type, "abs") == 0)
3934     globals->target2_reloc = R_ARM_ABS32;
3935   else if (strcmp (target2_type, "got-rel") == 0)
3936     globals->target2_reloc = R_ARM_GOT_PREL;
3937   else
3938     {
3939       _bfd_error_handler (_("Invalid TARGET2 relocation type '%s'."),
3940                           target2_type);
3941     }
3942   globals->fix_v4bx = fix_v4bx;
3943   globals->use_blx |= use_blx;
3944   globals->vfp11_fix = vfp11_fix;
3945   globals->pic_veneer = pic_veneer;
3946
3947   elf32_arm_tdata (output_bfd)->no_enum_size_warning = no_enum_warn;
3948 }
3949
3950 /* The thumb form of a long branch is a bit finicky, because the offset
3951    encoding is split over two fields, each in it's own instruction. They
3952    can occur in any order. So given a thumb form of long branch, and an
3953    offset, insert the offset into the thumb branch and return finished
3954    instruction.
3955
3956    It takes two thumb instructions to encode the target address. Each has
3957    11 bits to invest. The upper 11 bits are stored in one (identified by
3958    H-0.. see below), the lower 11 bits are stored in the other (identified
3959    by H-1).
3960
3961    Combine together and shifted left by 1 (it's a half word address) and
3962    there you have it.
3963
3964    Op: 1111 = F,
3965    H-0, upper address-0 = 000
3966    Op: 1111 = F,
3967    H-1, lower address-0 = 800
3968
3969    They can be ordered either way, but the arm tools I've seen always put
3970    the lower one first. It probably doesn't matter. krk@cygnus.com
3971
3972    XXX:  Actually the order does matter.  The second instruction (H-1)
3973    moves the computed address into the PC, so it must be the second one
3974    in the sequence.  The problem, however is that whilst little endian code
3975    stores the instructions in HI then LOW order, big endian code does the
3976    reverse.  nickc@cygnus.com.  */
3977
3978 #define LOW_HI_ORDER      0xF800F000
3979 #define HI_LOW_ORDER      0xF000F800
3980
3981 static insn32
3982 insert_thumb_branch (insn32 br_insn, int rel_off)
3983 {
3984   unsigned int low_bits;
3985   unsigned int high_bits;
3986
3987   BFD_ASSERT ((rel_off & 1) != 1);
3988
3989   rel_off >>= 1;                                /* Half word aligned address.  */
3990   low_bits = rel_off & 0x000007FF;              /* The bottom 11 bits.  */
3991   high_bits = (rel_off >> 11) & 0x000007FF;     /* The top 11 bits.  */
3992
3993   if ((br_insn & LOW_HI_ORDER) == LOW_HI_ORDER)
3994     br_insn = LOW_HI_ORDER | (low_bits << 16) | high_bits;
3995   else if ((br_insn & HI_LOW_ORDER) == HI_LOW_ORDER)
3996     br_insn = HI_LOW_ORDER | (high_bits << 16) | low_bits;
3997   else
3998     /* FIXME: abort is probably not the right call. krk@cygnus.com  */
3999     abort ();   /* Error - not a valid branch instruction form.  */
4000
4001   return br_insn;
4002 }
4003
4004
4005 /* Store an Arm insn into an output section not processed by
4006    elf32_arm_write_section.  */
4007
4008 static void
4009 put_arm_insn (struct elf32_arm_link_hash_table *htab,
4010              bfd * output_bfd, bfd_vma val, void * ptr)
4011 {
4012     if (htab->byteswap_code != bfd_little_endian (output_bfd))
4013       bfd_putl32 (val, ptr);
4014     else
4015       bfd_putb32 (val, ptr);
4016 }
4017
4018
4019 /* Store a 16-bit Thumb insn into an output section not processed by
4020    elf32_arm_write_section.  */
4021
4022 static void
4023 put_thumb_insn (struct elf32_arm_link_hash_table *htab,
4024                bfd * output_bfd, bfd_vma val, void * ptr)
4025 {
4026     if (htab->byteswap_code != bfd_little_endian (output_bfd))
4027       bfd_putl16 (val, ptr);
4028     else
4029       bfd_putb16 (val, ptr);
4030 }
4031
4032
4033 /* Thumb code calling an ARM function.  */
4034
4035 static int
4036 elf32_thumb_to_arm_stub (struct bfd_link_info * info,
4037                          const char *           name,
4038                          bfd *                  input_bfd,
4039                          bfd *                  output_bfd,
4040                          asection *             input_section,
4041                          bfd_byte *             hit_data,
4042                          asection *             sym_sec,
4043                          bfd_vma                offset,
4044                          bfd_signed_vma         addend,
4045                          bfd_vma                val,
4046                          char **error_message)
4047 {
4048   asection * s = 0;
4049   bfd_vma my_offset;
4050   unsigned long int tmp;
4051   long int ret_offset;
4052   struct elf_link_hash_entry * myh;
4053   struct elf32_arm_link_hash_table * globals;
4054
4055   myh = find_thumb_glue (info, name, error_message);
4056   if (myh == NULL)
4057     return FALSE;
4058
4059   globals = elf32_arm_hash_table (info);
4060
4061   BFD_ASSERT (globals != NULL);
4062   BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
4063
4064   my_offset = myh->root.u.def.value;
4065
4066   s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
4067                                THUMB2ARM_GLUE_SECTION_NAME);
4068
4069   BFD_ASSERT (s != NULL);
4070   BFD_ASSERT (s->contents != NULL);
4071   BFD_ASSERT (s->output_section != NULL);
4072
4073   if ((my_offset & 0x01) == 0x01)
4074     {
4075       if (sym_sec != NULL
4076           && sym_sec->owner != NULL
4077           && !INTERWORK_FLAG (sym_sec->owner))
4078         {
4079           (*_bfd_error_handler)
4080             (_("%B(%s): warning: interworking not enabled.\n"
4081                "  first occurrence: %B: thumb call to arm"),
4082              sym_sec->owner, input_bfd, name);
4083
4084           return FALSE;
4085         }
4086
4087       --my_offset;
4088       myh->root.u.def.value = my_offset;
4089
4090       put_thumb_insn (globals, output_bfd, (bfd_vma) t2a1_bx_pc_insn,
4091                       s->contents + my_offset);
4092
4093       put_thumb_insn (globals, output_bfd, (bfd_vma) t2a2_noop_insn,
4094                       s->contents + my_offset + 2);
4095
4096       ret_offset =
4097         /* Address of destination of the stub.  */
4098         ((bfd_signed_vma) val)
4099         - ((bfd_signed_vma)
4100            /* Offset from the start of the current section
4101               to the start of the stubs.  */
4102            (s->output_offset
4103             /* Offset of the start of this stub from the start of the stubs.  */
4104             + my_offset
4105             /* Address of the start of the current section.  */
4106             + s->output_section->vma)
4107            /* The branch instruction is 4 bytes into the stub.  */
4108            + 4
4109            /* ARM branches work from the pc of the instruction + 8.  */
4110            + 8);
4111
4112       put_arm_insn (globals, output_bfd,
4113                     (bfd_vma) t2a3_b_insn | ((ret_offset >> 2) & 0x00FFFFFF),
4114                     s->contents + my_offset + 4);
4115     }
4116
4117   BFD_ASSERT (my_offset <= globals->thumb_glue_size);
4118
4119   /* Now go back and fix up the original BL insn to point to here.  */
4120   ret_offset =
4121     /* Address of where the stub is located.  */
4122     (s->output_section->vma + s->output_offset + my_offset)
4123      /* Address of where the BL is located.  */
4124     - (input_section->output_section->vma + input_section->output_offset
4125        + offset)
4126     /* Addend in the relocation.  */
4127     - addend
4128     /* Biassing for PC-relative addressing.  */
4129     - 8;
4130
4131   tmp = bfd_get_32 (input_bfd, hit_data
4132                     - input_section->vma);
4133
4134   bfd_put_32 (output_bfd,
4135               (bfd_vma) insert_thumb_branch (tmp, ret_offset),
4136               hit_data - input_section->vma);
4137
4138   return TRUE;
4139 }
4140
4141 /* Populate an Arm to Thumb stub.  Returns the stub symbol.  */
4142
4143 static struct elf_link_hash_entry *
4144 elf32_arm_create_thumb_stub (struct bfd_link_info * info,
4145                              const char *           name,
4146                              bfd *                  input_bfd,
4147                              bfd *                  output_bfd,
4148                              asection *             sym_sec,
4149                              bfd_vma                val,
4150                              asection               *s,
4151                              char **error_message)
4152 {
4153   bfd_vma my_offset;
4154   long int ret_offset;
4155   struct elf_link_hash_entry * myh;
4156   struct elf32_arm_link_hash_table * globals;
4157
4158   myh = find_arm_glue (info, name, error_message);
4159   if (myh == NULL)
4160     return NULL;
4161
4162   globals = elf32_arm_hash_table (info);
4163
4164   BFD_ASSERT (globals != NULL);
4165   BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
4166
4167   my_offset = myh->root.u.def.value;
4168
4169   if ((my_offset & 0x01) == 0x01)
4170     {
4171       if (sym_sec != NULL
4172           && sym_sec->owner != NULL
4173           && !INTERWORK_FLAG (sym_sec->owner))
4174         {
4175           (*_bfd_error_handler)
4176             (_("%B(%s): warning: interworking not enabled.\n"
4177                "  first occurrence: %B: arm call to thumb"),
4178              sym_sec->owner, input_bfd, name);
4179         }
4180
4181       --my_offset;
4182       myh->root.u.def.value = my_offset;
4183
4184       if (info->shared || globals->root.is_relocatable_executable
4185           || globals->pic_veneer)
4186         {
4187           /* For relocatable objects we can't use absolute addresses,
4188              so construct the address from a relative offset.  */
4189           /* TODO: If the offset is small it's probably worth
4190              constructing the address with adds.  */
4191           put_arm_insn (globals, output_bfd, (bfd_vma) a2t1p_ldr_insn,
4192                         s->contents + my_offset);
4193           put_arm_insn (globals, output_bfd, (bfd_vma) a2t2p_add_pc_insn,
4194                         s->contents + my_offset + 4);
4195           put_arm_insn (globals, output_bfd, (bfd_vma) a2t3p_bx_r12_insn,
4196                         s->contents + my_offset + 8);
4197           /* Adjust the offset by 4 for the position of the add,
4198              and 8 for the pipeline offset.  */
4199           ret_offset = (val - (s->output_offset
4200                                + s->output_section->vma
4201                                + my_offset + 12))
4202                        | 1;
4203           bfd_put_32 (output_bfd, ret_offset,
4204                       s->contents + my_offset + 12);
4205         }
4206       else if (globals->use_blx)
4207         {
4208           put_arm_insn (globals, output_bfd, (bfd_vma) a2t1v5_ldr_insn,
4209                         s->contents + my_offset);
4210
4211           /* It's a thumb address.  Add the low order bit.  */
4212           bfd_put_32 (output_bfd, val | a2t2v5_func_addr_insn,
4213                       s->contents + my_offset + 4);
4214         }
4215       else
4216         {
4217           put_arm_insn (globals, output_bfd, (bfd_vma) a2t1_ldr_insn,
4218                         s->contents + my_offset);
4219
4220           put_arm_insn (globals, output_bfd, (bfd_vma) a2t2_bx_r12_insn,
4221                         s->contents + my_offset + 4);
4222
4223           /* It's a thumb address.  Add the low order bit.  */
4224           bfd_put_32 (output_bfd, val | a2t3_func_addr_insn,
4225                       s->contents + my_offset + 8);
4226         }
4227     }
4228
4229   BFD_ASSERT (my_offset <= globals->arm_glue_size);
4230
4231   return myh;
4232 }
4233
4234 /* Arm code calling a Thumb function.  */
4235
4236 static int
4237 elf32_arm_to_thumb_stub (struct bfd_link_info * info,
4238                          const char *           name,
4239                          bfd *                  input_bfd,
4240                          bfd *                  output_bfd,
4241                          asection *             input_section,
4242                          bfd_byte *             hit_data,
4243                          asection *             sym_sec,
4244                          bfd_vma                offset,
4245                          bfd_signed_vma         addend,
4246                          bfd_vma                val,
4247                          char **error_message)
4248 {
4249   unsigned long int tmp;
4250   bfd_vma my_offset;
4251   asection * s;
4252   long int ret_offset;
4253   struct elf_link_hash_entry * myh;
4254   struct elf32_arm_link_hash_table * globals;
4255
4256   globals = elf32_arm_hash_table (info);
4257
4258   BFD_ASSERT (globals != NULL);
4259   BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
4260
4261   s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
4262                                ARM2THUMB_GLUE_SECTION_NAME);
4263   BFD_ASSERT (s != NULL);
4264   BFD_ASSERT (s->contents != NULL);
4265   BFD_ASSERT (s->output_section != NULL);
4266
4267   myh = elf32_arm_create_thumb_stub (info, name, input_bfd, output_bfd,
4268                                      sym_sec, val, s, error_message);
4269   if (!myh)
4270     return FALSE;
4271
4272   my_offset = myh->root.u.def.value;
4273   tmp = bfd_get_32 (input_bfd, hit_data);
4274   tmp = tmp & 0xFF000000;
4275
4276   /* Somehow these are both 4 too far, so subtract 8.  */
4277   ret_offset = (s->output_offset
4278                 + my_offset
4279                 + s->output_section->vma
4280                 - (input_section->output_offset
4281                    + input_section->output_section->vma
4282                    + offset + addend)
4283                 - 8);
4284
4285   tmp = tmp | ((ret_offset >> 2) & 0x00FFFFFF);
4286
4287   bfd_put_32 (output_bfd, (bfd_vma) tmp, hit_data - input_section->vma);
4288
4289   return TRUE;
4290 }
4291
4292 /* Populate Arm stub for an exported Thumb function.  */
4293
4294 static bfd_boolean
4295 elf32_arm_to_thumb_export_stub (struct elf_link_hash_entry *h, void * inf)
4296 {
4297   struct bfd_link_info * info = (struct bfd_link_info *) inf;
4298   asection * s;
4299   struct elf_link_hash_entry * myh;
4300   struct elf32_arm_link_hash_entry *eh;
4301   struct elf32_arm_link_hash_table * globals;
4302   asection *sec;
4303   bfd_vma val;
4304   char *error_message;
4305
4306   eh = elf32_arm_hash_entry(h);
4307   /* Allocate stubs for exported Thumb functions on v4t.  */
4308   if (eh->export_glue == NULL)
4309     return TRUE;
4310
4311   globals = elf32_arm_hash_table (info);
4312
4313   BFD_ASSERT (globals != NULL);
4314   BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
4315
4316   s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
4317                                ARM2THUMB_GLUE_SECTION_NAME);
4318   BFD_ASSERT (s != NULL);
4319   BFD_ASSERT (s->contents != NULL);
4320   BFD_ASSERT (s->output_section != NULL);
4321
4322   sec = eh->export_glue->root.u.def.section;
4323
4324   BFD_ASSERT (sec->output_section != NULL);
4325
4326   val = eh->export_glue->root.u.def.value + sec->output_offset
4327         + sec->output_section->vma;
4328   myh = elf32_arm_create_thumb_stub (info, h->root.root.string,
4329                                      h->root.u.def.section->owner,
4330                                      globals->obfd, sec, val, s,
4331                                      &error_message);
4332   BFD_ASSERT (myh);
4333   return TRUE;
4334 }
4335
4336 /* Generate Arm stubs for exported Thumb symbols.  */
4337 static void
4338 elf32_arm_begin_write_processing (bfd *abfd ATTRIBUTE_UNUSED, 
4339                                   struct bfd_link_info *link_info)
4340 {
4341   struct elf32_arm_link_hash_table * globals;
4342
4343   if (!link_info)
4344     return;
4345
4346   globals = elf32_arm_hash_table (link_info);
4347   /* If blx is available then exported Thumb symbols are OK and there is
4348      nothing to do.  */
4349   if (globals->use_blx)
4350     return;
4351
4352   elf_link_hash_traverse (&globals->root, elf32_arm_to_thumb_export_stub,
4353                           link_info);
4354 }
4355
4356 /* Some relocations map to different relocations depending on the
4357    target.  Return the real relocation.  */
4358 static int
4359 arm_real_reloc_type (struct elf32_arm_link_hash_table * globals,
4360                      int r_type)
4361 {
4362   switch (r_type)
4363     {
4364     case R_ARM_TARGET1:
4365       if (globals->target1_is_rel)
4366         return R_ARM_REL32;
4367       else
4368         return R_ARM_ABS32;
4369
4370     case R_ARM_TARGET2:
4371       return globals->target2_reloc;
4372
4373     default:
4374       return r_type;
4375     }
4376 }
4377
4378 /* Return the base VMA address which should be subtracted from real addresses
4379    when resolving @dtpoff relocation.
4380    This is PT_TLS segment p_vaddr.  */
4381
4382 static bfd_vma
4383 dtpoff_base (struct bfd_link_info *info)
4384 {
4385   /* If tls_sec is NULL, we should have signalled an error already.  */
4386   if (elf_hash_table (info)->tls_sec == NULL)
4387     return 0;
4388   return elf_hash_table (info)->tls_sec->vma;
4389 }
4390
4391 /* Return the relocation value for @tpoff relocation
4392    if STT_TLS virtual address is ADDRESS.  */
4393
4394 static bfd_vma
4395 tpoff (struct bfd_link_info *info, bfd_vma address)
4396 {
4397   struct elf_link_hash_table *htab = elf_hash_table (info);
4398   bfd_vma base;
4399
4400   /* If tls_sec is NULL, we should have signalled an error already.  */
4401   if (htab->tls_sec == NULL)
4402     return 0;
4403   base = align_power ((bfd_vma) TCB_SIZE, htab->tls_sec->alignment_power);
4404   return address - htab->tls_sec->vma + base;
4405 }
4406
4407 /* Perform an R_ARM_ABS12 relocation on the field pointed to by DATA.
4408    VALUE is the relocation value.  */
4409
4410 static bfd_reloc_status_type
4411 elf32_arm_abs12_reloc (bfd *abfd, void *data, bfd_vma value)
4412 {
4413   if (value > 0xfff)
4414     return bfd_reloc_overflow;
4415
4416   value |= bfd_get_32 (abfd, data) & 0xfffff000;
4417   bfd_put_32 (abfd, value, data);
4418   return bfd_reloc_ok;
4419 }
4420
4421 /* For a given value of n, calculate the value of G_n as required to
4422    deal with group relocations.  We return it in the form of an
4423    encoded constant-and-rotation, together with the final residual.  If n is
4424    specified as less than zero, then final_residual is filled with the
4425    input value and no further action is performed.  */
4426
4427 static bfd_vma
4428 calculate_group_reloc_mask (bfd_vma value, int n, bfd_vma *final_residual)
4429 {
4430   int current_n;
4431   bfd_vma g_n;
4432   bfd_vma encoded_g_n = 0;
4433   bfd_vma residual = value; /* Also known as Y_n.  */
4434
4435   for (current_n = 0; current_n <= n; current_n++)
4436     {
4437       int shift;
4438
4439       /* Calculate which part of the value to mask.  */
4440       if (residual == 0)
4441         shift = 0;
4442       else
4443         {
4444           int msb;
4445
4446           /* Determine the most significant bit in the residual and
4447              align the resulting value to a 2-bit boundary.  */
4448           for (msb = 30; msb >= 0; msb -= 2)
4449             if (residual & (3 << msb))
4450               break;
4451
4452           /* The desired shift is now (msb - 6), or zero, whichever
4453              is the greater.  */
4454           shift = msb - 6;
4455           if (shift < 0)
4456             shift = 0;
4457         }
4458
4459       /* Calculate g_n in 32-bit as well as encoded constant+rotation form.  */
4460       g_n = residual & (0xff << shift);
4461       encoded_g_n = (g_n >> shift)
4462                     | ((g_n <= 0xff ? 0 : (32 - shift) / 2) << 8);
4463
4464       /* Calculate the residual for the next time around.  */
4465       residual &= ~g_n;
4466     }
4467
4468   *final_residual = residual;
4469
4470   return encoded_g_n;
4471 }
4472
4473 /* Given an ARM instruction, determine whether it is an ADD or a SUB.
4474    Returns 1 if it is an ADD, -1 if it is a SUB, and 0 otherwise.  */
4475 static int
4476 identify_add_or_sub(bfd_vma insn)
4477 {
4478   int opcode = insn & 0x1e00000;
4479
4480   if (opcode == 1 << 23) /* ADD */
4481     return 1;
4482
4483   if (opcode == 1 << 22) /* SUB */
4484     return -1;
4485
4486   return 0;
4487 }
4488
4489 /* Determine if we're dealing with a Thumb-2 object.  */
4490
4491 static int using_thumb2 (struct elf32_arm_link_hash_table *globals)
4492 {
4493   int arch = bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC,
4494                                        Tag_CPU_arch);
4495   return arch == TAG_CPU_ARCH_V6T2 || arch >= TAG_CPU_ARCH_V7;
4496 }
4497
4498 /* Perform a relocation as part of a final link.  */
4499
4500 static bfd_reloc_status_type
4501 elf32_arm_final_link_relocate (reloc_howto_type *           howto,
4502                                bfd *                        input_bfd,
4503                                bfd *                        output_bfd,
4504                                asection *                   input_section,
4505                                bfd_byte *                   contents,
4506                                Elf_Internal_Rela *          rel,
4507                                bfd_vma                      value,
4508                                struct bfd_link_info *       info,
4509                                asection *                   sym_sec,
4510                                const char *                 sym_name,
4511                                int                          sym_flags,
4512                                struct elf_link_hash_entry * h,
4513                                bfd_boolean *                unresolved_reloc_p,
4514                                char **error_message)
4515 {
4516   unsigned long                 r_type = howto->type;
4517   unsigned long                 r_symndx;
4518   bfd_byte *                    hit_data = contents + rel->r_offset;
4519   bfd *                         dynobj = NULL;
4520   Elf_Internal_Shdr *           symtab_hdr;
4521   struct elf_link_hash_entry ** sym_hashes;
4522   bfd_vma *                     local_got_offsets;
4523   asection *                    sgot = NULL;
4524   asection *                    splt = NULL;
4525   asection *                    sreloc = NULL;
4526   bfd_vma                       addend;
4527   bfd_signed_vma                signed_addend;
4528   struct elf32_arm_link_hash_table * globals;
4529
4530   globals = elf32_arm_hash_table (info);
4531
4532   /* Some relocation type map to different relocations depending on the
4533      target.  We pick the right one here.  */
4534   r_type = arm_real_reloc_type (globals, r_type);
4535   if (r_type != howto->type)
4536     howto = elf32_arm_howto_from_type (r_type);
4537
4538   /* If the start address has been set, then set the EF_ARM_HASENTRY
4539      flag.  Setting this more than once is redundant, but the cost is
4540      not too high, and it keeps the code simple.
4541
4542      The test is done  here, rather than somewhere else, because the
4543      start address is only set just before the final link commences.
4544
4545      Note - if the user deliberately sets a start address of 0, the
4546      flag will not be set.  */
4547   if (bfd_get_start_address (output_bfd) != 0)
4548     elf_elfheader (output_bfd)->e_flags |= EF_ARM_HASENTRY;
4549
4550   dynobj = elf_hash_table (info)->dynobj;
4551   if (dynobj)
4552     {
4553       sgot = bfd_get_section_by_name (dynobj, ".got");
4554       splt = bfd_get_section_by_name (dynobj, ".plt");
4555     }
4556   symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
4557   sym_hashes = elf_sym_hashes (input_bfd);
4558   local_got_offsets = elf_local_got_offsets (input_bfd);
4559   r_symndx = ELF32_R_SYM (rel->r_info);
4560
4561   if (globals->use_rel)
4562     {
4563       addend = bfd_get_32 (input_bfd, hit_data) & howto->src_mask;
4564
4565       if (addend & ((howto->src_mask + 1) >> 1))
4566         {
4567           signed_addend = -1;
4568           signed_addend &= ~ howto->src_mask;
4569           signed_addend |= addend;
4570         }
4571       else
4572         signed_addend = addend;
4573     }
4574   else
4575     addend = signed_addend = rel->r_addend;
4576
4577   switch (r_type)
4578     {
4579     case R_ARM_NONE:
4580       /* We don't need to find a value for this symbol.  It's just a
4581          marker.  */
4582       *unresolved_reloc_p = FALSE;
4583       return bfd_reloc_ok;
4584
4585     case R_ARM_ABS12:
4586       if (!globals->vxworks_p)
4587         return elf32_arm_abs12_reloc (input_bfd, hit_data, value + addend);
4588
4589     case R_ARM_PC24:
4590     case R_ARM_ABS32:
4591     case R_ARM_ABS32_NOI:
4592     case R_ARM_REL32:
4593     case R_ARM_REL32_NOI:
4594     case R_ARM_CALL:
4595     case R_ARM_JUMP24:
4596     case R_ARM_XPC25:
4597     case R_ARM_PREL31:
4598     case R_ARM_PLT32:
4599       /* Handle relocations which should use the PLT entry.  ABS32/REL32
4600          will use the symbol's value, which may point to a PLT entry, but we
4601          don't need to handle that here.  If we created a PLT entry, all
4602          branches in this object should go to it.  */
4603       if ((r_type != R_ARM_ABS32 && r_type != R_ARM_REL32
4604            && r_type != R_ARM_ABS32_NOI && r_type != R_ARM_REL32_NOI)
4605           && h != NULL
4606           && splt != NULL
4607           && h->plt.offset != (bfd_vma) -1)
4608         {
4609           /* If we've created a .plt section, and assigned a PLT entry to
4610              this function, it should not be known to bind locally.  If
4611              it were, we would have cleared the PLT entry.  */
4612           BFD_ASSERT (!SYMBOL_CALLS_LOCAL (info, h));
4613
4614           value = (splt->output_section->vma
4615                    + splt->output_offset
4616                    + h->plt.offset);
4617           *unresolved_reloc_p = FALSE;
4618           return _bfd_final_link_relocate (howto, input_bfd, input_section,
4619                                            contents, rel->r_offset, value,
4620                                            rel->r_addend);
4621         }
4622
4623       /* When generating a shared object or relocatable executable, these
4624          relocations are copied into the output file to be resolved at
4625          run time.  */
4626       if ((info->shared || globals->root.is_relocatable_executable)
4627           && (input_section->flags & SEC_ALLOC)
4628           && ((r_type != R_ARM_REL32 && r_type != R_ARM_REL32_NOI)
4629               || !SYMBOL_CALLS_LOCAL (info, h))
4630           && (h == NULL
4631               || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
4632               || h->root.type != bfd_link_hash_undefweak)
4633           && r_type != R_ARM_PC24
4634           && r_type != R_ARM_CALL
4635           && r_type != R_ARM_JUMP24
4636           && r_type != R_ARM_PREL31
4637           && r_type != R_ARM_PLT32)
4638         {
4639           Elf_Internal_Rela outrel;
4640           bfd_byte *loc;
4641           bfd_boolean skip, relocate;
4642
4643           *unresolved_reloc_p = FALSE;
4644
4645           if (sreloc == NULL)
4646             {
4647               const char * name;
4648
4649               name = (bfd_elf_string_from_elf_section
4650                       (input_bfd,
4651                        elf_elfheader (input_bfd)->e_shstrndx,
4652                        elf_section_data (input_section)->rel_hdr.sh_name));
4653               if (name == NULL)
4654                 return bfd_reloc_notsupported;
4655
4656               BFD_ASSERT (reloc_section_p (globals, name, input_section));
4657
4658               sreloc = bfd_get_section_by_name (dynobj, name);
4659               BFD_ASSERT (sreloc != NULL);
4660             }
4661
4662           skip = FALSE;
4663           relocate = FALSE;
4664
4665           outrel.r_addend = addend;
4666           outrel.r_offset =
4667             _bfd_elf_section_offset (output_bfd, info, input_section,
4668                                      rel->r_offset);
4669           if (outrel.r_offset == (bfd_vma) -1)
4670             skip = TRUE;
4671           else if (outrel.r_offset == (bfd_vma) -2)
4672             skip = TRUE, relocate = TRUE;
4673           outrel.r_offset += (input_section->output_section->vma
4674                               + input_section->output_offset);
4675
4676           if (skip)
4677             memset (&outrel, 0, sizeof outrel);
4678           else if (h != NULL
4679                    && h->dynindx != -1
4680                    && (!info->shared
4681                        || !info->symbolic
4682                        || !h->def_regular))
4683             outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
4684           else
4685             {
4686               int symbol;
4687
4688               /* This symbol is local, or marked to become local.  */
4689               if (sym_flags == STT_ARM_TFUNC)
4690                 value |= 1;
4691               if (globals->symbian_p)
4692                 {
4693                   asection *osec;
4694
4695                   /* On Symbian OS, the data segment and text segement
4696                      can be relocated independently.  Therefore, we
4697                      must indicate the segment to which this
4698                      relocation is relative.  The BPABI allows us to
4699                      use any symbol in the right segment; we just use
4700                      the section symbol as it is convenient.  (We
4701                      cannot use the symbol given by "h" directly as it
4702                      will not appear in the dynamic symbol table.)
4703
4704                      Note that the dynamic linker ignores the section
4705                      symbol value, so we don't subtract osec->vma
4706                      from the emitted reloc addend.  */
4707                   if (sym_sec)
4708                     osec = sym_sec->output_section;
4709                   else
4710                     osec = input_section->output_section;
4711                   symbol = elf_section_data (osec)->dynindx;
4712                   if (symbol == 0)
4713                     {
4714                       struct elf_link_hash_table *htab = elf_hash_table (info);
4715
4716                       if ((osec->flags & SEC_READONLY) == 0
4717                           && htab->data_index_section != NULL)
4718                         osec = htab->data_index_section;
4719                       else
4720                         osec = htab->text_index_section;
4721                       symbol = elf_section_data (osec)->dynindx;
4722                     }
4723                   BFD_ASSERT (symbol != 0);
4724                 }
4725               else
4726                 /* On SVR4-ish systems, the dynamic loader cannot
4727                    relocate the text and data segments independently,
4728                    so the symbol does not matter.  */
4729                 symbol = 0;
4730               outrel.r_info = ELF32_R_INFO (symbol, R_ARM_RELATIVE);
4731               if (globals->use_rel)
4732                 relocate = TRUE;
4733               else
4734                 outrel.r_addend += value;
4735             }
4736
4737           loc = sreloc->contents;
4738           loc += sreloc->reloc_count++ * RELOC_SIZE (globals);
4739           SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
4740
4741           /* If this reloc is against an external symbol, we do not want to
4742              fiddle with the addend.  Otherwise, we need to include the symbol
4743              value so that it becomes an addend for the dynamic reloc.  */
4744           if (! relocate)
4745             return bfd_reloc_ok;
4746
4747           return _bfd_final_link_relocate (howto, input_bfd, input_section,
4748                                            contents, rel->r_offset, value,
4749                                            (bfd_vma) 0);
4750         }
4751       else switch (r_type)
4752         {
4753         case R_ARM_ABS12:
4754           return elf32_arm_abs12_reloc (input_bfd, hit_data, value + addend);
4755
4756         case R_ARM_XPC25:         /* Arm BLX instruction.  */
4757         case R_ARM_CALL:
4758         case R_ARM_JUMP24:
4759         case R_ARM_PC24:          /* Arm B/BL instruction */
4760         case R_ARM_PLT32:
4761           if (r_type == R_ARM_XPC25)
4762             {
4763               /* Check for Arm calling Arm function.  */
4764               /* FIXME: Should we translate the instruction into a BL
4765                  instruction instead ?  */
4766               if (sym_flags != STT_ARM_TFUNC)
4767                 (*_bfd_error_handler)
4768                   (_("\%B: Warning: Arm BLX instruction targets Arm function '%s'."),
4769                    input_bfd,
4770                    h ? h->root.root.string : "(local)");
4771             }
4772           else if (r_type != R_ARM_CALL || !globals->use_blx)
4773             {
4774               /* Check for Arm calling Thumb function.  */
4775               if (sym_flags == STT_ARM_TFUNC)
4776                 {
4777                   if (elf32_arm_to_thumb_stub (info, sym_name, input_bfd,
4778                                                output_bfd, input_section,
4779                                                hit_data, sym_sec, rel->r_offset,
4780                                                signed_addend, value,
4781                                                error_message))
4782                     return bfd_reloc_ok;
4783                   else
4784                     return bfd_reloc_dangerous;
4785                 }
4786             }
4787
4788           /* The ARM ELF ABI says that this reloc is computed as: S - P + A
4789              where:
4790               S is the address of the symbol in the relocation.
4791               P is address of the instruction being relocated.
4792               A is the addend (extracted from the instruction) in bytes.
4793
4794              S is held in 'value'.
4795              P is the base address of the section containing the
4796                instruction plus the offset of the reloc into that
4797                section, ie:
4798                  (input_section->output_section->vma +
4799                   input_section->output_offset +
4800                   rel->r_offset).
4801              A is the addend, converted into bytes, ie:
4802                  (signed_addend * 4)
4803
4804              Note: None of these operations have knowledge of the pipeline
4805              size of the processor, thus it is up to the assembler to
4806              encode this information into the addend.  */
4807           value -= (input_section->output_section->vma
4808                     + input_section->output_offset);
4809           value -= rel->r_offset;
4810           if (globals->use_rel)
4811             value += (signed_addend << howto->size);
4812           else
4813             /* RELA addends do not have to be adjusted by howto->size.  */
4814             value += signed_addend;
4815
4816           signed_addend = value;
4817           signed_addend >>= howto->rightshift;
4818
4819           /* A branch to an undefined weak symbol is turned into a jump to
4820              the next instruction.  */
4821           if (h && h->root.type == bfd_link_hash_undefweak)
4822             {
4823               value = (bfd_get_32 (input_bfd, hit_data) & 0xf0000000)
4824                       | 0x0affffff;
4825             }
4826           else
4827             {
4828               /* Perform a signed range check.  */
4829               if (   signed_addend >   ((bfd_signed_vma)  (howto->dst_mask >> 1))
4830                   || signed_addend < - ((bfd_signed_vma) ((howto->dst_mask + 1) >> 1)))
4831                 return bfd_reloc_overflow;
4832
4833               addend = (value & 2);
4834
4835               value = (signed_addend & howto->dst_mask)
4836                 | (bfd_get_32 (input_bfd, hit_data) & (~ howto->dst_mask));
4837
4838               /* Set the H bit in the BLX instruction.  */
4839               if (sym_flags == STT_ARM_TFUNC)
4840                 {
4841                   if (addend)
4842                     value |= (1 << 24);
4843                   else
4844                     value &= ~(bfd_vma)(1 << 24);
4845                 }
4846               if (r_type == R_ARM_CALL)
4847                 {
4848                   /* Select the correct instruction (BL or BLX).  */
4849                   if (sym_flags == STT_ARM_TFUNC)
4850                     value |= (1 << 28);
4851                   else
4852                     {
4853                       value &= ~(bfd_vma)(1 << 28);
4854                       value |= (1 << 24);
4855                     }
4856                 }
4857             }
4858           break;
4859
4860         case R_ARM_ABS32:
4861           value += addend;
4862           if (sym_flags == STT_ARM_TFUNC)
4863             value |= 1;
4864           break;
4865
4866         case R_ARM_ABS32_NOI:
4867           value += addend;
4868           break;
4869
4870         case R_ARM_REL32:
4871           value += addend;
4872           if (sym_flags == STT_ARM_TFUNC)
4873             value |= 1;
4874           value -= (input_section->output_section->vma
4875                     + input_section->output_offset + rel->r_offset);
4876           break;
4877
4878         case R_ARM_REL32_NOI:
4879           value += addend;
4880           value -= (input_section->output_section->vma
4881                     + input_section->output_offset + rel->r_offset);
4882           break;
4883
4884         case R_ARM_PREL31:
4885           value -= (input_section->output_section->vma
4886                     + input_section->output_offset + rel->r_offset);
4887           value += signed_addend;
4888           if (! h || h->root.type != bfd_link_hash_undefweak)
4889             {
4890               /* Check for overflow */
4891               if ((value ^ (value >> 1)) & (1 << 30))
4892                 return bfd_reloc_overflow;
4893             }
4894           value &= 0x7fffffff;
4895           value |= (bfd_get_32 (input_bfd, hit_data) & 0x80000000);
4896           if (sym_flags == STT_ARM_TFUNC)
4897             value |= 1;
4898           break;
4899         }
4900
4901       bfd_put_32 (input_bfd, value, hit_data);
4902       return bfd_reloc_ok;
4903
4904     case R_ARM_ABS8:
4905       value += addend;
4906       if ((long) value > 0x7f || (long) value < -0x80)
4907         return bfd_reloc_overflow;
4908
4909       bfd_put_8 (input_bfd, value, hit_data);
4910       return bfd_reloc_ok;
4911
4912     case R_ARM_ABS16:
4913       value += addend;
4914
4915       if ((long) value > 0x7fff || (long) value < -0x8000)
4916         return bfd_reloc_overflow;
4917
4918       bfd_put_16 (input_bfd, value, hit_data);
4919       return bfd_reloc_ok;
4920
4921     case R_ARM_THM_ABS5:
4922       /* Support ldr and str instructions for the thumb.  */
4923       if (globals->use_rel)
4924         {
4925           /* Need to refetch addend.  */
4926           addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask;
4927           /* ??? Need to determine shift amount from operand size.  */
4928           addend >>= howto->rightshift;
4929         }
4930       value += addend;
4931
4932       /* ??? Isn't value unsigned?  */
4933       if ((long) value > 0x1f || (long) value < -0x10)
4934         return bfd_reloc_overflow;
4935
4936       /* ??? Value needs to be properly shifted into place first.  */
4937       value |= bfd_get_16 (input_bfd, hit_data) & 0xf83f;
4938       bfd_put_16 (input_bfd, value, hit_data);
4939       return bfd_reloc_ok;
4940
4941     case R_ARM_THM_ALU_PREL_11_0:
4942       /* Corresponds to: addw.w reg, pc, #offset (and similarly for subw).  */
4943       {
4944         bfd_vma insn;
4945         bfd_signed_vma relocation;
4946
4947         insn = (bfd_get_16 (input_bfd, hit_data) << 16)
4948              | bfd_get_16 (input_bfd, hit_data + 2);
4949
4950         if (globals->use_rel)
4951           {
4952             signed_addend = (insn & 0xff) | ((insn & 0x7000) >> 4)
4953                           | ((insn & (1 << 26)) >> 15);
4954             if (insn & 0xf00000)
4955               signed_addend = -signed_addend;
4956           }
4957
4958         relocation = value + signed_addend;
4959         relocation -= (input_section->output_section->vma
4960                        + input_section->output_offset
4961                        + rel->r_offset);
4962
4963         value = llabs (relocation);
4964
4965         if (value >= 0x1000)
4966           return bfd_reloc_overflow;
4967
4968         insn = (insn & 0xfb0f8f00) | (value & 0xff)
4969              | ((value & 0x700) << 4)
4970              | ((value & 0x800) << 15);
4971         if (relocation < 0)
4972           insn |= 0xa00000;
4973
4974         bfd_put_16 (input_bfd, insn >> 16, hit_data);
4975         bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
4976
4977         return bfd_reloc_ok;
4978       }
4979
4980     case R_ARM_THM_PC12:
4981       /* Corresponds to: ldr.w reg, [pc, #offset].  */
4982       {
4983         bfd_vma insn;
4984         bfd_signed_vma relocation;
4985
4986         insn = (bfd_get_16 (input_bfd, hit_data) << 16)
4987              | bfd_get_16 (input_bfd, hit_data + 2);
4988
4989         if (globals->use_rel)
4990           {
4991             signed_addend = insn & 0xfff;
4992             if (!(insn & (1 << 23)))
4993               signed_addend = -signed_addend;
4994           }
4995
4996         relocation = value + signed_addend;
4997         relocation -= (input_section->output_section->vma
4998                        + input_section->output_offset
4999                        + rel->r_offset);
5000
5001         value = llabs (relocation);
5002
5003         if (value >= 0x1000)
5004           return bfd_reloc_overflow;
5005
5006         insn = (insn & 0xff7ff000) | value;
5007         if (relocation >= 0)
5008           insn |= (1 << 23);
5009
5010         bfd_put_16 (input_bfd, insn >> 16, hit_data);
5011         bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
5012
5013         return bfd_reloc_ok;
5014       }
5015
5016     case R_ARM_THM_XPC22:
5017     case R_ARM_THM_CALL:
5018       /* Thumb BL (branch long instruction).  */
5019       {
5020         bfd_vma relocation;
5021         bfd_vma reloc_sign;
5022         bfd_boolean overflow = FALSE;
5023         bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
5024         bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
5025         bfd_signed_vma reloc_signed_max;
5026         bfd_signed_vma reloc_signed_min;
5027         bfd_vma check;
5028         bfd_signed_vma signed_check;
5029         int bitsize;
5030         int thumb2 = using_thumb2 (globals);
5031
5032         /* A branch to an undefined weak symbol is turned into a jump to
5033            the next instruction.  */
5034         if (h && h->root.type == bfd_link_hash_undefweak)
5035           {
5036             bfd_put_16 (input_bfd, 0xe000, hit_data);
5037             bfd_put_16 (input_bfd, 0xbf00, hit_data + 2);
5038             return bfd_reloc_ok;
5039           }
5040
5041         /* Fetch the addend.  We use the Thumb-2 encoding (backwards compatible
5042            with Thumb-1) involving the J1 and J2 bits.  */
5043         if (globals->use_rel)
5044           {
5045             bfd_vma s = (upper_insn & (1 << 10)) >> 10;
5046             bfd_vma upper = upper_insn & 0x3ff;
5047             bfd_vma lower = lower_insn & 0x7ff;
5048             bfd_vma j1 = (lower_insn & (1 << 13)) >> 13;
5049             bfd_vma j2 = (lower_insn & (1 << 11)) >> 11;
5050             bfd_vma i1 = j1 ^ s ? 0 : 1;
5051             bfd_vma i2 = j2 ^ s ? 0 : 1;
5052
5053             addend = (i1 << 23) | (i2 << 22) | (upper << 12) | (lower << 1);
5054             /* Sign extend.  */
5055             addend = (addend | ((s ? 0 : 1) << 24)) - (1 << 24);
5056
5057             signed_addend = addend;
5058           }
5059
5060         if (r_type == R_ARM_THM_XPC22)
5061           {
5062             /* Check for Thumb to Thumb call.  */
5063             /* FIXME: Should we translate the instruction into a BL
5064                instruction instead ?  */
5065             if (sym_flags == STT_ARM_TFUNC)
5066               (*_bfd_error_handler)
5067                 (_("%B: Warning: Thumb BLX instruction targets thumb function '%s'."),
5068                  input_bfd,
5069                  h ? h->root.root.string : "(local)");
5070           }
5071         else
5072           {
5073             /* If it is not a call to Thumb, assume call to Arm.
5074                If it is a call relative to a section name, then it is not a
5075                function call at all, but rather a long jump.  Calls through
5076                the PLT do not require stubs.  */
5077             if (sym_flags != STT_ARM_TFUNC && sym_flags != STT_SECTION
5078                 && (h == NULL || splt == NULL
5079                     || h->plt.offset == (bfd_vma) -1))
5080               {
5081                 if (globals->use_blx)
5082                   {
5083                     /* Convert BL to BLX.  */
5084                     lower_insn = (lower_insn & ~0x1000) | 0x0800;
5085                   }
5086                 else if (elf32_thumb_to_arm_stub
5087                     (info, sym_name, input_bfd, output_bfd, input_section,
5088                      hit_data, sym_sec, rel->r_offset, signed_addend, value,
5089                      error_message))
5090                   return bfd_reloc_ok;
5091                 else
5092                   return bfd_reloc_dangerous;
5093               }
5094             else if (sym_flags == STT_ARM_TFUNC && globals->use_blx)
5095               {
5096                 /* Make sure this is a BL.  */
5097                 lower_insn |= 0x1800;
5098               }
5099           }
5100
5101         /* Handle calls via the PLT.  */
5102         if (h != NULL && splt != NULL && h->plt.offset != (bfd_vma) -1)
5103           {
5104             value = (splt->output_section->vma
5105                      + splt->output_offset
5106                      + h->plt.offset);
5107             if (globals->use_blx)
5108               {
5109                 /* If the Thumb BLX instruction is available, convert the
5110                    BL to a BLX instruction to call the ARM-mode PLT entry.  */
5111                 lower_insn = (lower_insn & ~0x1000) | 0x0800;
5112               }
5113             else
5114               /* Target the Thumb stub before the ARM PLT entry.  */
5115               value -= PLT_THUMB_STUB_SIZE;
5116             *unresolved_reloc_p = FALSE;
5117           }
5118
5119         relocation = value + signed_addend;
5120
5121         relocation -= (input_section->output_section->vma
5122                        + input_section->output_offset
5123                        + rel->r_offset);
5124
5125         check = relocation >> howto->rightshift;
5126
5127         /* If this is a signed value, the rightshift just dropped
5128            leading 1 bits (assuming twos complement).  */
5129         if ((bfd_signed_vma) relocation >= 0)
5130           signed_check = check;
5131         else
5132           signed_check = check | ~((bfd_vma) -1 >> howto->rightshift);
5133
5134         /* Calculate the permissable maximum and minimum values for
5135            this relocation according to whether we're relocating for
5136            Thumb-2 or not.  */
5137         bitsize = howto->bitsize;
5138         if (!thumb2)
5139           bitsize -= 2;
5140         reloc_signed_max = ((1 << (bitsize - 1)) - 1) >> howto->rightshift;
5141         reloc_signed_min = ~reloc_signed_max;
5142
5143         /* Assumes two's complement.  */
5144         if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
5145           overflow = TRUE;
5146
5147         if ((lower_insn & 0x1800) == 0x0800)
5148           /* For a BLX instruction, make sure that the relocation is rounded up
5149              to a word boundary.  This follows the semantics of the instruction
5150              which specifies that bit 1 of the target address will come from bit
5151              1 of the base address.  */
5152           relocation = (relocation + 2) & ~ 3;
5153
5154         /* Put RELOCATION back into the insn.  Assumes two's complement.
5155            We use the Thumb-2 encoding, which is safe even if dealing with
5156            a Thumb-1 instruction by virtue of our overflow check above.  */
5157         reloc_sign = (signed_check < 0) ? 1 : 0;
5158         upper_insn = (upper_insn & ~(bfd_vma) 0x7ff)
5159                      | ((relocation >> 12) & 0x3ff)
5160                      | (reloc_sign << 10);
5161         lower_insn = (lower_insn & ~(bfd_vma) 0x2fff) 
5162                      | (((!((relocation >> 23) & 1)) ^ reloc_sign) << 13)
5163                      | (((!((relocation >> 22) & 1)) ^ reloc_sign) << 11)
5164                      | ((relocation >> 1) & 0x7ff);
5165
5166         /* Put the relocated value back in the object file:  */
5167         bfd_put_16 (input_bfd, upper_insn, hit_data);
5168         bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
5169
5170         return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
5171       }
5172       break;
5173
5174     case R_ARM_THM_JUMP24:
5175       /* Thumb32 unconditional branch instruction.  */
5176       {
5177         bfd_vma relocation;
5178         bfd_boolean overflow = FALSE;
5179         bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
5180         bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
5181         bfd_signed_vma reloc_signed_max = ((1 << (howto->bitsize - 1)) - 1) >> howto->rightshift;
5182         bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
5183         bfd_vma check;
5184         bfd_signed_vma signed_check;
5185
5186         /* Need to refetch the addend, reconstruct the top three bits, and glue the
5187            two pieces together.  */
5188         if (globals->use_rel)
5189           {
5190             bfd_vma S  = (upper_insn & 0x0400) >> 10;
5191             bfd_vma hi = (upper_insn & 0x03ff);
5192             bfd_vma I1 = (lower_insn & 0x2000) >> 13;
5193             bfd_vma I2 = (lower_insn & 0x0800) >> 11;
5194             bfd_vma lo = (lower_insn & 0x07ff);
5195
5196             I1 = !(I1 ^ S);
5197             I2 = !(I2 ^ S);
5198             S  = !S;
5199
5200             signed_addend = (S << 24) | (I1 << 23) | (I2 << 22) | (hi << 12) | (lo << 1);
5201             signed_addend -= (1 << 24); /* Sign extend.  */
5202           }
5203
5204         /* ??? Should handle interworking?  GCC might someday try to
5205            use this for tail calls.  */
5206
5207         relocation = value + signed_addend;
5208         relocation -= (input_section->output_section->vma
5209                        + input_section->output_offset
5210                        + rel->r_offset);
5211
5212         check = relocation >> howto->rightshift;
5213
5214         /* If this is a signed value, the rightshift just dropped
5215            leading 1 bits (assuming twos complement).  */
5216         if ((bfd_signed_vma) relocation >= 0)
5217           signed_check = check;
5218         else
5219           signed_check = check | ~((bfd_vma) -1 >> howto->rightshift);
5220
5221         /* Assumes two's complement.  */
5222         if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
5223           overflow = TRUE;
5224
5225         /* Put RELOCATION back into the insn.  */
5226         {
5227           bfd_vma S  = (relocation & 0x01000000) >> 24;
5228           bfd_vma I1 = (relocation & 0x00800000) >> 23;
5229           bfd_vma I2 = (relocation & 0x00400000) >> 22;
5230           bfd_vma hi = (relocation & 0x003ff000) >> 12;
5231           bfd_vma lo = (relocation & 0x00000ffe) >>  1;
5232
5233           I1 = !(I1 ^ S);
5234           I2 = !(I2 ^ S);
5235
5236           upper_insn = (upper_insn & (bfd_vma) 0xf800) | (S << 10) | hi;
5237           lower_insn = (lower_insn & (bfd_vma) 0xd000) | (I1 << 13) | (I2 << 11) | lo;
5238         }
5239
5240         /* Put the relocated value back in the object file:  */
5241         bfd_put_16 (input_bfd, upper_insn, hit_data);
5242         bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
5243
5244         return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
5245       }
5246
5247     case R_ARM_THM_JUMP19:
5248       /* Thumb32 conditional branch instruction.  */
5249       {
5250         bfd_vma relocation;
5251         bfd_boolean overflow = FALSE;
5252         bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
5253         bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
5254         bfd_signed_vma reloc_signed_max = 0xffffe;
5255         bfd_signed_vma reloc_signed_min = -0x100000;
5256         bfd_signed_vma signed_check;
5257
5258         /* Need to refetch the addend, reconstruct the top three bits,
5259            and squish the two 11 bit pieces together.  */
5260         if (globals->use_rel)
5261           {
5262             bfd_vma S     = (upper_insn & 0x0400) >> 10;
5263             bfd_vma upper = (upper_insn & 0x003f);
5264             bfd_vma J1    = (lower_insn & 0x2000) >> 13;
5265             bfd_vma J2    = (lower_insn & 0x0800) >> 11;
5266             bfd_vma lower = (lower_insn & 0x07ff);
5267
5268             upper |= J1 << 6;
5269             upper |= J2 << 7;
5270             upper |= (!S) << 8;
5271             upper -= 0x0100; /* Sign extend.  */
5272
5273             addend = (upper << 12) | (lower << 1);
5274             signed_addend = addend;
5275           }
5276
5277         /* ??? Should handle interworking?  GCC might someday try to
5278            use this for tail calls.  */
5279
5280         relocation = value + signed_addend;
5281         relocation -= (input_section->output_section->vma
5282                        + input_section->output_offset
5283                        + rel->r_offset);
5284         signed_check = (bfd_signed_vma) relocation;
5285
5286         if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
5287           overflow = TRUE;
5288
5289         /* Put RELOCATION back into the insn.  */
5290         {
5291           bfd_vma S  = (relocation & 0x00100000) >> 20;
5292           bfd_vma J2 = (relocation & 0x00080000) >> 19;
5293           bfd_vma J1 = (relocation & 0x00040000) >> 18;
5294           bfd_vma hi = (relocation & 0x0003f000) >> 12;
5295           bfd_vma lo = (relocation & 0x00000ffe) >>  1;
5296
5297           upper_insn = (upper_insn & 0xfbc0) | (S << 10) | hi;
5298           lower_insn = (lower_insn & 0xd000) | (J1 << 13) | (J2 << 11) | lo;
5299         }
5300
5301         /* Put the relocated value back in the object file:  */
5302         bfd_put_16 (input_bfd, upper_insn, hit_data);
5303         bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
5304
5305         return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
5306       }
5307
5308     case R_ARM_THM_JUMP11:
5309     case R_ARM_THM_JUMP8:
5310     case R_ARM_THM_JUMP6:
5311       /* Thumb B (branch) instruction).  */
5312       {
5313         bfd_signed_vma relocation;
5314         bfd_signed_vma reloc_signed_max = (1 << (howto->bitsize - 1)) - 1;
5315         bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
5316         bfd_signed_vma signed_check;
5317
5318         /* CZB cannot jump backward.  */
5319         if (r_type == R_ARM_THM_JUMP6)
5320           reloc_signed_min = 0;
5321
5322         if (globals->use_rel)
5323           {
5324             /* Need to refetch addend.  */
5325             addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask;
5326             if (addend & ((howto->src_mask + 1) >> 1))
5327               {
5328                 signed_addend = -1;
5329                 signed_addend &= ~ howto->src_mask;
5330                 signed_addend |= addend;
5331               }
5332             else
5333               signed_addend = addend;
5334             /* The value in the insn has been right shifted.  We need to
5335                undo this, so that we can perform the address calculation
5336                in terms of bytes.  */
5337             signed_addend <<= howto->rightshift;
5338           }
5339         relocation = value + signed_addend;
5340
5341         relocation -= (input_section->output_section->vma
5342                        + input_section->output_offset
5343                        + rel->r_offset);
5344
5345         relocation >>= howto->rightshift;
5346         signed_check = relocation;
5347
5348         if (r_type == R_ARM_THM_JUMP6)
5349           relocation = ((relocation & 0x0020) << 4) | ((relocation & 0x001f) << 3);
5350         else
5351           relocation &= howto->dst_mask;
5352         relocation |= (bfd_get_16 (input_bfd, hit_data) & (~ howto->dst_mask));
5353
5354         bfd_put_16 (input_bfd, relocation, hit_data);
5355
5356         /* Assumes two's complement.  */
5357         if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
5358           return bfd_reloc_overflow;
5359
5360         return bfd_reloc_ok;
5361       }
5362
5363     case R_ARM_ALU_PCREL7_0:
5364     case R_ARM_ALU_PCREL15_8:
5365     case R_ARM_ALU_PCREL23_15:
5366       {
5367         bfd_vma insn;
5368         bfd_vma relocation;
5369
5370         insn = bfd_get_32 (input_bfd, hit_data);
5371         if (globals->use_rel)
5372           {
5373             /* Extract the addend.  */
5374             addend = (insn & 0xff) << ((insn & 0xf00) >> 7);
5375             signed_addend = addend;
5376           }
5377         relocation = value + signed_addend;
5378
5379         relocation -= (input_section->output_section->vma
5380                        + input_section->output_offset
5381                        + rel->r_offset);
5382         insn = (insn & ~0xfff)
5383                | ((howto->bitpos << 7) & 0xf00)
5384                | ((relocation >> howto->bitpos) & 0xff);
5385         bfd_put_32 (input_bfd, value, hit_data);
5386       }
5387       return bfd_reloc_ok;
5388
5389     case R_ARM_GNU_VTINHERIT:
5390     case R_ARM_GNU_VTENTRY:
5391       return bfd_reloc_ok;
5392
5393     case R_ARM_GOTOFF32:
5394       /* Relocation is relative to the start of the
5395          global offset table.  */
5396
5397       BFD_ASSERT (sgot != NULL);
5398       if (sgot == NULL)
5399         return bfd_reloc_notsupported;
5400
5401       /* If we are addressing a Thumb function, we need to adjust the
5402          address by one, so that attempts to call the function pointer will
5403          correctly interpret it as Thumb code.  */
5404       if (sym_flags == STT_ARM_TFUNC)
5405         value += 1;
5406
5407       /* Note that sgot->output_offset is not involved in this
5408          calculation.  We always want the start of .got.  If we
5409          define _GLOBAL_OFFSET_TABLE in a different way, as is
5410          permitted by the ABI, we might have to change this
5411          calculation.  */
5412       value -= sgot->output_section->vma;
5413       return _bfd_final_link_relocate (howto, input_bfd, input_section,
5414                                        contents, rel->r_offset, value,
5415                                        rel->r_addend);
5416
5417     case R_ARM_GOTPC:
5418       /* Use global offset table as symbol value.  */
5419       BFD_ASSERT (sgot != NULL);
5420
5421       if (sgot == NULL)
5422         return bfd_reloc_notsupported;
5423
5424       *unresolved_reloc_p = FALSE;
5425       value = sgot->output_section->vma;
5426       return _bfd_final_link_relocate (howto, input_bfd, input_section,
5427                                        contents, rel->r_offset, value,
5428                                        rel->r_addend);
5429
5430     case R_ARM_GOT32:
5431     case R_ARM_GOT_PREL:
5432       /* Relocation is to the entry for this symbol in the
5433          global offset table.  */
5434       if (sgot == NULL)
5435         return bfd_reloc_notsupported;
5436
5437       if (h != NULL)
5438         {
5439           bfd_vma off;
5440           bfd_boolean dyn;
5441
5442           off = h->got.offset;
5443           BFD_ASSERT (off != (bfd_vma) -1);
5444           dyn = globals->root.dynamic_sections_created;
5445
5446           if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
5447               || (info->shared
5448                   && SYMBOL_REFERENCES_LOCAL (info, h))
5449               || (ELF_ST_VISIBILITY (h->other)
5450                   && h->root.type == bfd_link_hash_undefweak))
5451             {
5452               /* This is actually a static link, or it is a -Bsymbolic link
5453                  and the symbol is defined locally.  We must initialize this
5454                  entry in the global offset table.  Since the offset must
5455                  always be a multiple of 4, we use the least significant bit
5456                  to record whether we have initialized it already.
5457
5458                  When doing a dynamic link, we create a .rel(a).got relocation
5459                  entry to initialize the value.  This is done in the
5460                  finish_dynamic_symbol routine.  */
5461               if ((off & 1) != 0)
5462                 off &= ~1;
5463               else
5464                 {
5465                   /* If we are addressing a Thumb function, we need to
5466                      adjust the address by one, so that attempts to
5467                      call the function pointer will correctly
5468                      interpret it as Thumb code.  */
5469                   if (sym_flags == STT_ARM_TFUNC)
5470                     value |= 1;
5471
5472                   bfd_put_32 (output_bfd, value, sgot->contents + off);
5473                   h->got.offset |= 1;
5474                 }
5475             }
5476           else
5477             *unresolved_reloc_p = FALSE;
5478
5479           value = sgot->output_offset + off;
5480         }
5481       else
5482         {
5483           bfd_vma off;
5484
5485           BFD_ASSERT (local_got_offsets != NULL &&
5486                       local_got_offsets[r_symndx] != (bfd_vma) -1);
5487
5488           off = local_got_offsets[r_symndx];
5489
5490           /* The offset must always be a multiple of 4.  We use the
5491              least significant bit to record whether we have already
5492              generated the necessary reloc.  */
5493           if ((off & 1) != 0)
5494             off &= ~1;
5495           else
5496             {
5497               /* If we are addressing a Thumb function, we need to
5498                  adjust the address by one, so that attempts to
5499                  call the function pointer will correctly
5500                  interpret it as Thumb code.  */
5501               if (sym_flags == STT_ARM_TFUNC)
5502                 value |= 1;
5503
5504               if (globals->use_rel)
5505                 bfd_put_32 (output_bfd, value, sgot->contents + off);
5506
5507               if (info->shared)
5508                 {
5509                   asection * srelgot;
5510                   Elf_Internal_Rela outrel;
5511                   bfd_byte *loc;
5512
5513                   srelgot = (bfd_get_section_by_name
5514                              (dynobj, RELOC_SECTION (globals, ".got")));
5515                   BFD_ASSERT (srelgot != NULL);
5516
5517                   outrel.r_addend = addend + value;
5518                   outrel.r_offset = (sgot->output_section->vma
5519                                      + sgot->output_offset
5520                                      + off);
5521                   outrel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
5522                   loc = srelgot->contents;
5523                   loc += srelgot->reloc_count++ * RELOC_SIZE (globals);
5524                   SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
5525                 }
5526
5527               local_got_offsets[r_symndx] |= 1;
5528             }
5529
5530           value = sgot->output_offset + off;
5531         }
5532       if (r_type != R_ARM_GOT32)
5533         value += sgot->output_section->vma;
5534
5535       return _bfd_final_link_relocate (howto, input_bfd, input_section,
5536                                        contents, rel->r_offset, value,
5537                                        rel->r_addend);
5538
5539     case R_ARM_TLS_LDO32:
5540       value = value - dtpoff_base (info);
5541
5542       return _bfd_final_link_relocate (howto, input_bfd, input_section,
5543                                        contents, rel->r_offset, value,
5544                                        rel->r_addend);
5545
5546     case R_ARM_TLS_LDM32:
5547       {
5548         bfd_vma off;
5549
5550         if (globals->sgot == NULL)
5551           abort ();
5552
5553         off = globals->tls_ldm_got.offset;
5554
5555         if ((off & 1) != 0)
5556           off &= ~1;
5557         else
5558           {
5559             /* If we don't know the module number, create a relocation
5560                for it.  */
5561             if (info->shared)
5562               {
5563                 Elf_Internal_Rela outrel;
5564                 bfd_byte *loc;
5565
5566                 if (globals->srelgot == NULL)
5567                   abort ();
5568
5569                 outrel.r_addend = 0;
5570                 outrel.r_offset = (globals->sgot->output_section->vma
5571                                    + globals->sgot->output_offset + off);
5572                 outrel.r_info = ELF32_R_INFO (0, R_ARM_TLS_DTPMOD32);
5573
5574                 if (globals->use_rel)
5575                   bfd_put_32 (output_bfd, outrel.r_addend,
5576                               globals->sgot->contents + off);
5577
5578                 loc = globals->srelgot->contents;
5579                 loc += globals->srelgot->reloc_count++ * RELOC_SIZE (globals);
5580                 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
5581               }
5582             else
5583               bfd_put_32 (output_bfd, 1, globals->sgot->contents + off);
5584
5585             globals->tls_ldm_got.offset |= 1;
5586           }
5587
5588         value = globals->sgot->output_section->vma + globals->sgot->output_offset + off 
5589           - (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
5590
5591         return _bfd_final_link_relocate (howto, input_bfd, input_section,
5592                                          contents, rel->r_offset, value,
5593                                          rel->r_addend);
5594       }
5595
5596     case R_ARM_TLS_GD32:
5597     case R_ARM_TLS_IE32:
5598       {
5599         bfd_vma off;
5600         int indx;
5601         char tls_type;
5602
5603         if (globals->sgot == NULL)
5604           abort ();
5605
5606         indx = 0;
5607         if (h != NULL)
5608           {
5609             bfd_boolean dyn;
5610             dyn = globals->root.dynamic_sections_created;
5611             if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
5612                 && (!info->shared
5613                     || !SYMBOL_REFERENCES_LOCAL (info, h)))
5614               {
5615                 *unresolved_reloc_p = FALSE;
5616                 indx = h->dynindx;
5617               }
5618             off = h->got.offset;
5619             tls_type = ((struct elf32_arm_link_hash_entry *) h)->tls_type;
5620           }
5621         else
5622           {
5623             if (local_got_offsets == NULL)
5624               abort ();
5625             off = local_got_offsets[r_symndx];
5626             tls_type = elf32_arm_local_got_tls_type (input_bfd)[r_symndx];
5627           }
5628
5629         if (tls_type == GOT_UNKNOWN)
5630           abort ();
5631
5632         if ((off & 1) != 0)
5633           off &= ~1;
5634         else
5635           {
5636             bfd_boolean need_relocs = FALSE;
5637             Elf_Internal_Rela outrel;
5638             bfd_byte *loc = NULL;
5639             int cur_off = off;
5640
5641             /* The GOT entries have not been initialized yet.  Do it
5642                now, and emit any relocations.  If both an IE GOT and a
5643                GD GOT are necessary, we emit the GD first.  */
5644
5645             if ((info->shared || indx != 0)
5646                 && (h == NULL
5647                     || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
5648                     || h->root.type != bfd_link_hash_undefweak))
5649               {
5650                 need_relocs = TRUE;
5651                 if (globals->srelgot == NULL)
5652                   abort ();
5653                 loc = globals->srelgot->contents;
5654                 loc += globals->srelgot->reloc_count * RELOC_SIZE (globals);
5655               }
5656
5657             if (tls_type & GOT_TLS_GD)
5658               {
5659                 if (need_relocs)
5660                   {
5661                     outrel.r_addend = 0;
5662                     outrel.r_offset = (globals->sgot->output_section->vma
5663                                        + globals->sgot->output_offset
5664                                        + cur_off);
5665                     outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_DTPMOD32);
5666
5667                     if (globals->use_rel)
5668                       bfd_put_32 (output_bfd, outrel.r_addend,
5669                                   globals->sgot->contents + cur_off);
5670
5671                     SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
5672                     globals->srelgot->reloc_count++;
5673                     loc += RELOC_SIZE (globals);
5674
5675                     if (indx == 0)
5676                       bfd_put_32 (output_bfd, value - dtpoff_base (info),
5677                                   globals->sgot->contents + cur_off + 4);
5678                     else
5679                       {
5680                         outrel.r_addend = 0;
5681                         outrel.r_info = ELF32_R_INFO (indx,
5682                                                       R_ARM_TLS_DTPOFF32);
5683                         outrel.r_offset += 4;
5684
5685                         if (globals->use_rel)
5686                           bfd_put_32 (output_bfd, outrel.r_addend,
5687                                       globals->sgot->contents + cur_off + 4);
5688
5689
5690                         SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
5691                         globals->srelgot->reloc_count++;
5692                         loc += RELOC_SIZE (globals);
5693                       }
5694                   }
5695                 else
5696                   {
5697                     /* If we are not emitting relocations for a
5698                        general dynamic reference, then we must be in a
5699                        static link or an executable link with the
5700                        symbol binding locally.  Mark it as belonging
5701                        to module 1, the executable.  */
5702                     bfd_put_32 (output_bfd, 1,
5703                                 globals->sgot->contents + cur_off);
5704                     bfd_put_32 (output_bfd, value - dtpoff_base (info),
5705                                 globals->sgot->contents + cur_off + 4);
5706                   }
5707
5708                 cur_off += 8;
5709               }
5710
5711             if (tls_type & GOT_TLS_IE)
5712               {
5713                 if (need_relocs)
5714                   {
5715                     if (indx == 0)
5716                       outrel.r_addend = value - dtpoff_base (info);
5717                     else
5718                       outrel.r_addend = 0;
5719                     outrel.r_offset = (globals->sgot->output_section->vma
5720                                        + globals->sgot->output_offset
5721                                        + cur_off);
5722                     outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_TPOFF32);
5723
5724                     if (globals->use_rel)
5725                       bfd_put_32 (output_bfd, outrel.r_addend,
5726                                   globals->sgot->contents + cur_off);
5727
5728                     SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
5729                     globals->srelgot->reloc_count++;
5730                     loc += RELOC_SIZE (globals);
5731                   }
5732                 else
5733                   bfd_put_32 (output_bfd, tpoff (info, value),
5734                               globals->sgot->contents + cur_off);
5735                 cur_off += 4;
5736               }
5737
5738             if (h != NULL)
5739               h->got.offset |= 1;
5740             else
5741               local_got_offsets[r_symndx] |= 1;
5742           }
5743
5744         if ((tls_type & GOT_TLS_GD) && r_type != R_ARM_TLS_GD32)
5745           off += 8;
5746         value = globals->sgot->output_section->vma + globals->sgot->output_offset + off 
5747           - (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
5748
5749         return _bfd_final_link_relocate (howto, input_bfd, input_section,
5750                                          contents, rel->r_offset, value,
5751                                          rel->r_addend);
5752       }
5753
5754     case R_ARM_TLS_LE32:
5755       if (info->shared)
5756         {
5757           (*_bfd_error_handler)
5758             (_("%B(%A+0x%lx): R_ARM_TLS_LE32 relocation not permitted in shared object"),
5759              input_bfd, input_section,
5760              (long) rel->r_offset, howto->name);
5761           return FALSE;   
5762         }
5763       else
5764         value = tpoff (info, value);
5765       
5766       return _bfd_final_link_relocate (howto, input_bfd, input_section,
5767                                        contents, rel->r_offset, value,
5768                                        rel->r_addend);
5769
5770     case R_ARM_V4BX:
5771       if (globals->fix_v4bx)
5772         {
5773           bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
5774
5775           /* Ensure that we have a BX instruction.  */
5776           BFD_ASSERT ((insn & 0x0ffffff0) == 0x012fff10);
5777
5778           /* Preserve Rm (lowest four bits) and the condition code
5779              (highest four bits). Other bits encode MOV PC,Rm.  */
5780           insn = (insn & 0xf000000f) | 0x01a0f000;
5781
5782           bfd_put_32 (input_bfd, insn, hit_data);
5783         }
5784       return bfd_reloc_ok;
5785
5786     case R_ARM_MOVW_ABS_NC:
5787     case R_ARM_MOVT_ABS:
5788     case R_ARM_MOVW_PREL_NC:
5789     case R_ARM_MOVT_PREL:
5790     /* Until we properly support segment-base-relative addressing then
5791        we assume the segment base to be zero, as for the group relocations.
5792        Thus R_ARM_MOVW_BREL_NC has the same semantics as R_ARM_MOVW_ABS_NC
5793        and R_ARM_MOVT_BREL has the same semantics as R_ARM_MOVT_ABS.  */
5794     case R_ARM_MOVW_BREL_NC:
5795     case R_ARM_MOVW_BREL:
5796     case R_ARM_MOVT_BREL:
5797       {
5798         bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
5799
5800         if (globals->use_rel)
5801           {
5802             addend = ((insn >> 4) & 0xf000) | (insn & 0xfff);
5803             signed_addend = (addend ^ 0x8000) - 0x8000;
5804           }
5805
5806         value += signed_addend;
5807
5808         if (r_type == R_ARM_MOVW_PREL_NC || r_type == R_ARM_MOVT_PREL)
5809           value -= (input_section->output_section->vma
5810                     + input_section->output_offset + rel->r_offset);
5811
5812         if (r_type == R_ARM_MOVW_BREL && value >= 0x10000)
5813           return bfd_reloc_overflow;
5814
5815         if (sym_flags == STT_ARM_TFUNC)
5816           value |= 1;
5817
5818         if (r_type == R_ARM_MOVT_ABS || r_type == R_ARM_MOVT_PREL
5819             || r_type == R_ARM_MOVT_BREL)
5820           value >>= 16;
5821
5822         insn &= 0xfff0f000;
5823         insn |= value & 0xfff;
5824         insn |= (value & 0xf000) << 4;
5825         bfd_put_32 (input_bfd, insn, hit_data);
5826       }
5827       return bfd_reloc_ok;
5828
5829     case R_ARM_THM_MOVW_ABS_NC:
5830     case R_ARM_THM_MOVT_ABS:
5831     case R_ARM_THM_MOVW_PREL_NC:
5832     case R_ARM_THM_MOVT_PREL:
5833     /* Until we properly support segment-base-relative addressing then
5834        we assume the segment base to be zero, as for the above relocations.
5835        Thus R_ARM_THM_MOVW_BREL_NC has the same semantics as
5836        R_ARM_THM_MOVW_ABS_NC and R_ARM_THM_MOVT_BREL has the same semantics
5837        as R_ARM_THM_MOVT_ABS.  */
5838     case R_ARM_THM_MOVW_BREL_NC:
5839     case R_ARM_THM_MOVW_BREL:
5840     case R_ARM_THM_MOVT_BREL:
5841       {
5842         bfd_vma insn;
5843         
5844         insn = bfd_get_16 (input_bfd, hit_data) << 16;
5845         insn |= bfd_get_16 (input_bfd, hit_data + 2);
5846
5847         if (globals->use_rel)
5848           {
5849             addend = ((insn >> 4)  & 0xf000)
5850                    | ((insn >> 15) & 0x0800)
5851                    | ((insn >> 4)  & 0x0700)
5852                    | (insn         & 0x00ff);
5853             signed_addend = (addend ^ 0x10000) - 0x10000;
5854           }
5855
5856         value += signed_addend;
5857
5858         if (r_type == R_ARM_THM_MOVW_PREL_NC || r_type == R_ARM_THM_MOVT_PREL)
5859           value -= (input_section->output_section->vma
5860                     + input_section->output_offset + rel->r_offset);
5861
5862         if (r_type == R_ARM_THM_MOVW_BREL && value >= 0x10000)
5863           return bfd_reloc_overflow;
5864
5865         if (sym_flags == STT_ARM_TFUNC)
5866           value |= 1;
5867
5868         if (r_type == R_ARM_THM_MOVT_ABS || r_type == R_ARM_THM_MOVT_PREL
5869             || r_type == R_ARM_THM_MOVT_BREL)
5870           value >>= 16;
5871
5872         insn &= 0xfbf08f00;
5873         insn |= (value & 0xf000) << 4;
5874         insn |= (value & 0x0800) << 15;
5875         insn |= (value & 0x0700) << 4;
5876         insn |= (value & 0x00ff);
5877
5878         bfd_put_16 (input_bfd, insn >> 16, hit_data);
5879         bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
5880       }
5881       return bfd_reloc_ok;
5882
5883     case R_ARM_ALU_PC_G0_NC:
5884     case R_ARM_ALU_PC_G1_NC:
5885     case R_ARM_ALU_PC_G0:
5886     case R_ARM_ALU_PC_G1:
5887     case R_ARM_ALU_PC_G2:
5888     case R_ARM_ALU_SB_G0_NC:
5889     case R_ARM_ALU_SB_G1_NC:
5890     case R_ARM_ALU_SB_G0:
5891     case R_ARM_ALU_SB_G1:
5892     case R_ARM_ALU_SB_G2:
5893       {
5894         bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
5895         bfd_vma pc = input_section->output_section->vma
5896                      + input_section->output_offset + rel->r_offset;
5897         /* sb should be the origin of the *segment* containing the symbol.
5898            It is not clear how to obtain this OS-dependent value, so we
5899            make an arbitrary choice of zero.  */
5900         bfd_vma sb = 0;
5901         bfd_vma residual;
5902         bfd_vma g_n;
5903         bfd_signed_vma signed_value;
5904         int group = 0;
5905
5906         /* Determine which group of bits to select.  */
5907         switch (r_type)
5908           {
5909           case R_ARM_ALU_PC_G0_NC:
5910           case R_ARM_ALU_PC_G0:
5911           case R_ARM_ALU_SB_G0_NC:
5912           case R_ARM_ALU_SB_G0:
5913             group = 0;
5914             break;
5915
5916           case R_ARM_ALU_PC_G1_NC:
5917           case R_ARM_ALU_PC_G1:
5918           case R_ARM_ALU_SB_G1_NC:
5919           case R_ARM_ALU_SB_G1:
5920             group = 1;
5921             break;
5922
5923           case R_ARM_ALU_PC_G2:
5924           case R_ARM_ALU_SB_G2:
5925             group = 2;
5926             break;
5927
5928           default:
5929             abort();
5930           }
5931
5932         /* If REL, extract the addend from the insn.  If RELA, it will
5933            have already been fetched for us.  */
5934         if (globals->use_rel)
5935           {
5936             int negative;
5937             bfd_vma constant = insn & 0xff;
5938             bfd_vma rotation = (insn & 0xf00) >> 8;
5939
5940             if (rotation == 0)
5941               signed_addend = constant;
5942             else
5943               {
5944                 /* Compensate for the fact that in the instruction, the
5945                    rotation is stored in multiples of 2 bits.  */
5946                 rotation *= 2;
5947
5948                 /* Rotate "constant" right by "rotation" bits.  */
5949                 signed_addend = (constant >> rotation) |
5950                                 (constant << (8 * sizeof (bfd_vma) - rotation));
5951               }
5952
5953             /* Determine if the instruction is an ADD or a SUB.
5954                (For REL, this determines the sign of the addend.)  */
5955             negative = identify_add_or_sub (insn);
5956             if (negative == 0)
5957               {
5958                 (*_bfd_error_handler)
5959                   (_("%B(%A+0x%lx): Only ADD or SUB instructions are allowed for ALU group relocations"),
5960                   input_bfd, input_section,
5961                   (long) rel->r_offset, howto->name);
5962                 return bfd_reloc_overflow;        
5963               }
5964
5965             signed_addend *= negative;
5966           }
5967
5968         /* Compute the value (X) to go in the place.  */
5969         if (r_type == R_ARM_ALU_PC_G0_NC
5970             || r_type == R_ARM_ALU_PC_G1_NC
5971             || r_type == R_ARM_ALU_PC_G0
5972             || r_type == R_ARM_ALU_PC_G1
5973             || r_type == R_ARM_ALU_PC_G2)
5974           /* PC relative.  */
5975           signed_value = value - pc + signed_addend;
5976         else
5977           /* Section base relative.  */
5978           signed_value = value - sb + signed_addend;
5979
5980         /* If the target symbol is a Thumb function, then set the
5981            Thumb bit in the address.  */
5982         if (sym_flags == STT_ARM_TFUNC)
5983           signed_value |= 1;
5984
5985         /* Calculate the value of the relevant G_n, in encoded
5986            constant-with-rotation format.  */
5987         g_n = calculate_group_reloc_mask (llabs (signed_value), group,
5988                                           &residual);
5989
5990         /* Check for overflow if required.  */
5991         if ((r_type == R_ARM_ALU_PC_G0
5992              || r_type == R_ARM_ALU_PC_G1
5993              || r_type == R_ARM_ALU_PC_G2
5994              || r_type == R_ARM_ALU_SB_G0
5995              || r_type == R_ARM_ALU_SB_G1
5996              || r_type == R_ARM_ALU_SB_G2) && residual != 0)
5997           {
5998             (*_bfd_error_handler)
5999               (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
6000               input_bfd, input_section,
6001               (long) rel->r_offset, llabs (signed_value), howto->name);
6002             return bfd_reloc_overflow;
6003           }
6004
6005         /* Mask out the value and the ADD/SUB part of the opcode; take care
6006            not to destroy the S bit.  */
6007         insn &= 0xff1ff000;
6008
6009         /* Set the opcode according to whether the value to go in the
6010            place is negative.  */
6011         if (signed_value < 0)
6012           insn |= 1 << 22;
6013         else
6014           insn |= 1 << 23;
6015
6016         /* Encode the offset.  */
6017         insn |= g_n;
6018
6019         bfd_put_32 (input_bfd, insn, hit_data);
6020       }
6021       return bfd_reloc_ok;
6022
6023     case R_ARM_LDR_PC_G0:
6024     case R_ARM_LDR_PC_G1:
6025     case R_ARM_LDR_PC_G2:
6026     case R_ARM_LDR_SB_G0:
6027     case R_ARM_LDR_SB_G1:
6028     case R_ARM_LDR_SB_G2:
6029       {
6030         bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
6031         bfd_vma pc = input_section->output_section->vma
6032                      + input_section->output_offset + rel->r_offset;
6033         bfd_vma sb = 0; /* See note above.  */
6034         bfd_vma residual;
6035         bfd_signed_vma signed_value;
6036         int group = 0;
6037
6038         /* Determine which groups of bits to calculate.  */
6039         switch (r_type)
6040           {
6041           case R_ARM_LDR_PC_G0:
6042           case R_ARM_LDR_SB_G0:
6043             group = 0;
6044             break;
6045
6046           case R_ARM_LDR_PC_G1:
6047           case R_ARM_LDR_SB_G1:
6048             group = 1;
6049             break;
6050
6051           case R_ARM_LDR_PC_G2:
6052           case R_ARM_LDR_SB_G2:
6053             group = 2;
6054             break;
6055
6056           default:
6057             abort();
6058           }
6059
6060         /* If REL, extract the addend from the insn.  If RELA, it will
6061            have already been fetched for us.  */
6062         if (globals->use_rel)
6063           {
6064             int negative = (insn & (1 << 23)) ? 1 : -1;
6065             signed_addend = negative * (insn & 0xfff);
6066           }
6067
6068         /* Compute the value (X) to go in the place.  */
6069         if (r_type == R_ARM_LDR_PC_G0
6070             || r_type == R_ARM_LDR_PC_G1
6071             || r_type == R_ARM_LDR_PC_G2)
6072           /* PC relative.  */
6073           signed_value = value - pc + signed_addend;
6074         else
6075           /* Section base relative.  */
6076           signed_value = value - sb + signed_addend;
6077
6078         /* Calculate the value of the relevant G_{n-1} to obtain
6079            the residual at that stage.  */
6080         calculate_group_reloc_mask (llabs (signed_value), group - 1, &residual);
6081
6082         /* Check for overflow.  */
6083         if (residual >= 0x1000)
6084           {
6085             (*_bfd_error_handler)
6086               (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
6087               input_bfd, input_section,
6088               (long) rel->r_offset, llabs (signed_value), howto->name);
6089             return bfd_reloc_overflow;
6090           }
6091
6092         /* Mask out the value and U bit.  */
6093         insn &= 0xff7ff000;
6094
6095         /* Set the U bit if the value to go in the place is non-negative.  */
6096         if (signed_value >= 0)
6097           insn |= 1 << 23;
6098
6099         /* Encode the offset.  */
6100         insn |= residual;
6101
6102         bfd_put_32 (input_bfd, insn, hit_data);
6103       }
6104       return bfd_reloc_ok;
6105
6106     case R_ARM_LDRS_PC_G0:
6107     case R_ARM_LDRS_PC_G1:
6108     case R_ARM_LDRS_PC_G2:
6109     case R_ARM_LDRS_SB_G0:
6110     case R_ARM_LDRS_SB_G1:
6111     case R_ARM_LDRS_SB_G2:
6112       {
6113         bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
6114         bfd_vma pc = input_section->output_section->vma
6115                      + input_section->output_offset + rel->r_offset;
6116         bfd_vma sb = 0; /* See note above.  */
6117         bfd_vma residual;
6118         bfd_signed_vma signed_value;
6119         int group = 0;
6120
6121         /* Determine which groups of bits to calculate.  */
6122         switch (r_type)
6123           {
6124           case R_ARM_LDRS_PC_G0:
6125           case R_ARM_LDRS_SB_G0:
6126             group = 0;
6127             break;
6128
6129           case R_ARM_LDRS_PC_G1:
6130           case R_ARM_LDRS_SB_G1:
6131             group = 1;
6132             break;
6133
6134           case R_ARM_LDRS_PC_G2:
6135           case R_ARM_LDRS_SB_G2:
6136             group = 2;
6137             break;
6138
6139           default:
6140             abort();
6141           }
6142
6143         /* If REL, extract the addend from the insn.  If RELA, it will
6144            have already been fetched for us.  */
6145         if (globals->use_rel)
6146           {
6147             int negative = (insn & (1 << 23)) ? 1 : -1;
6148             signed_addend = negative * (((insn & 0xf00) >> 4) + (insn & 0xf));
6149           }
6150
6151         /* Compute the value (X) to go in the place.  */
6152         if (r_type == R_ARM_LDRS_PC_G0
6153             || r_type == R_ARM_LDRS_PC_G1
6154             || r_type == R_ARM_LDRS_PC_G2)
6155           /* PC relative.  */
6156           signed_value = value - pc + signed_addend;
6157         else
6158           /* Section base relative.  */
6159           signed_value = value - sb + signed_addend;
6160
6161         /* Calculate the value of the relevant G_{n-1} to obtain
6162            the residual at that stage.  */
6163         calculate_group_reloc_mask (llabs (signed_value), group - 1, &residual);
6164
6165         /* Check for overflow.  */
6166         if (residual >= 0x100)
6167           {
6168             (*_bfd_error_handler)
6169               (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
6170               input_bfd, input_section,
6171               (long) rel->r_offset, llabs (signed_value), howto->name);
6172             return bfd_reloc_overflow;
6173           }
6174
6175         /* Mask out the value and U bit.  */
6176         insn &= 0xff7ff0f0;
6177
6178         /* Set the U bit if the value to go in the place is non-negative.  */
6179         if (signed_value >= 0)
6180           insn |= 1 << 23;
6181
6182         /* Encode the offset.  */
6183         insn |= ((residual & 0xf0) << 4) | (residual & 0xf);
6184
6185         bfd_put_32 (input_bfd, insn, hit_data);
6186       }
6187       return bfd_reloc_ok;
6188
6189     case R_ARM_LDC_PC_G0:
6190     case R_ARM_LDC_PC_G1:
6191     case R_ARM_LDC_PC_G2:
6192     case R_ARM_LDC_SB_G0:
6193     case R_ARM_LDC_SB_G1:
6194     case R_ARM_LDC_SB_G2:
6195       {
6196         bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
6197         bfd_vma pc = input_section->output_section->vma
6198                      + input_section->output_offset + rel->r_offset;
6199         bfd_vma sb = 0; /* See note above.  */
6200         bfd_vma residual;
6201         bfd_signed_vma signed_value;
6202         int group = 0;
6203
6204         /* Determine which groups of bits to calculate.  */
6205         switch (r_type)
6206           {
6207           case R_ARM_LDC_PC_G0:
6208           case R_ARM_LDC_SB_G0:
6209             group = 0;
6210             break;
6211
6212           case R_ARM_LDC_PC_G1:
6213           case R_ARM_LDC_SB_G1:
6214             group = 1;
6215             break;
6216
6217           case R_ARM_LDC_PC_G2:
6218           case R_ARM_LDC_SB_G2:
6219             group = 2;
6220             break;
6221
6222           default:
6223             abort();
6224           }
6225
6226         /* If REL, extract the addend from the insn.  If RELA, it will
6227            have already been fetched for us.  */
6228         if (globals->use_rel)
6229           {
6230             int negative = (insn & (1 << 23)) ? 1 : -1;
6231             signed_addend = negative * ((insn & 0xff) << 2);
6232           }
6233
6234         /* Compute the value (X) to go in the place.  */
6235         if (r_type == R_ARM_LDC_PC_G0
6236             || r_type == R_ARM_LDC_PC_G1
6237             || r_type == R_ARM_LDC_PC_G2)
6238           /* PC relative.  */
6239           signed_value = value - pc + signed_addend;
6240         else
6241           /* Section base relative.  */
6242           signed_value = value - sb + signed_addend;
6243
6244         /* Calculate the value of the relevant G_{n-1} to obtain
6245            the residual at that stage.  */
6246         calculate_group_reloc_mask (llabs (signed_value), group - 1, &residual);
6247
6248         /* Check for overflow.  (The absolute value to go in the place must be
6249            divisible by four and, after having been divided by four, must
6250            fit in eight bits.)  */
6251         if ((residual & 0x3) != 0 || residual >= 0x400)
6252           {
6253             (*_bfd_error_handler)
6254               (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
6255               input_bfd, input_section,
6256               (long) rel->r_offset, llabs (signed_value), howto->name);
6257             return bfd_reloc_overflow;
6258           }
6259
6260         /* Mask out the value and U bit.  */
6261         insn &= 0xff7fff00;
6262
6263         /* Set the U bit if the value to go in the place is non-negative.  */
6264         if (signed_value >= 0)
6265           insn |= 1 << 23;
6266
6267         /* Encode the offset.  */
6268         insn |= residual >> 2;
6269
6270         bfd_put_32 (input_bfd, insn, hit_data);
6271       }
6272       return bfd_reloc_ok;
6273
6274     default:
6275       return bfd_reloc_notsupported;
6276     }
6277 }
6278
6279 /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS.  */
6280 static void
6281 arm_add_to_rel (bfd *              abfd,
6282                 bfd_byte *         address,
6283                 reloc_howto_type * howto,
6284                 bfd_signed_vma     increment)
6285 {
6286   bfd_signed_vma addend;
6287
6288   if (howto->type == R_ARM_THM_CALL)
6289     {
6290       int upper_insn, lower_insn;
6291       int upper, lower;
6292
6293       upper_insn = bfd_get_16 (abfd, address);
6294       lower_insn = bfd_get_16 (abfd, address + 2);
6295       upper = upper_insn & 0x7ff;
6296       lower = lower_insn & 0x7ff;
6297
6298       addend = (upper << 12) | (lower << 1);
6299       addend += increment;
6300       addend >>= 1;
6301
6302       upper_insn = (upper_insn & 0xf800) | ((addend >> 11) & 0x7ff);
6303       lower_insn = (lower_insn & 0xf800) | (addend & 0x7ff);
6304
6305       bfd_put_16 (abfd, (bfd_vma) upper_insn, address);
6306       bfd_put_16 (abfd, (bfd_vma) lower_insn, address + 2);
6307     }
6308   else
6309     {
6310       bfd_vma        contents;
6311
6312       contents = bfd_get_32 (abfd, address);
6313
6314       /* Get the (signed) value from the instruction.  */
6315       addend = contents & howto->src_mask;
6316       if (addend & ((howto->src_mask + 1) >> 1))
6317         {
6318           bfd_signed_vma mask;
6319
6320           mask = -1;
6321           mask &= ~ howto->src_mask;
6322           addend |= mask;
6323         }
6324
6325       /* Add in the increment, (which is a byte value).  */
6326       switch (howto->type)
6327         {
6328         default:
6329           addend += increment;
6330           break;
6331
6332         case R_ARM_PC24:
6333         case R_ARM_PLT32:
6334         case R_ARM_CALL:
6335         case R_ARM_JUMP24:
6336           addend <<= howto->size;
6337           addend += increment;
6338
6339           /* Should we check for overflow here ?  */
6340
6341           /* Drop any undesired bits.  */
6342           addend >>= howto->rightshift;
6343           break;
6344         }
6345
6346       contents = (contents & ~ howto->dst_mask) | (addend & howto->dst_mask);
6347
6348       bfd_put_32 (abfd, contents, address);
6349     }
6350 }
6351
6352 #define IS_ARM_TLS_RELOC(R_TYPE)        \
6353   ((R_TYPE) == R_ARM_TLS_GD32           \
6354    || (R_TYPE) == R_ARM_TLS_LDO32       \
6355    || (R_TYPE) == R_ARM_TLS_LDM32       \
6356    || (R_TYPE) == R_ARM_TLS_DTPOFF32    \
6357    || (R_TYPE) == R_ARM_TLS_DTPMOD32    \
6358    || (R_TYPE) == R_ARM_TLS_TPOFF32     \
6359    || (R_TYPE) == R_ARM_TLS_LE32        \
6360    || (R_TYPE) == R_ARM_TLS_IE32)
6361
6362 /* Relocate an ARM ELF section.  */
6363 static bfd_boolean
6364 elf32_arm_relocate_section (bfd *                  output_bfd,
6365                             struct bfd_link_info * info,
6366                             bfd *                  input_bfd,
6367                             asection *             input_section,
6368                             bfd_byte *             contents,
6369                             Elf_Internal_Rela *    relocs,
6370                             Elf_Internal_Sym *     local_syms,
6371                             asection **            local_sections)
6372 {
6373   Elf_Internal_Shdr *symtab_hdr;
6374   struct elf_link_hash_entry **sym_hashes;
6375   Elf_Internal_Rela *rel;
6376   Elf_Internal_Rela *relend;
6377   const char *name;
6378   struct elf32_arm_link_hash_table * globals;
6379
6380   globals = elf32_arm_hash_table (info);
6381
6382   symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
6383   sym_hashes = elf_sym_hashes (input_bfd);
6384
6385   rel = relocs;
6386   relend = relocs + input_section->reloc_count;
6387   for (; rel < relend; rel++)
6388     {
6389       int                          r_type;
6390       reloc_howto_type *           howto;
6391       unsigned long                r_symndx;
6392       Elf_Internal_Sym *           sym;
6393       asection *                   sec;
6394       struct elf_link_hash_entry * h;
6395       bfd_vma                      relocation;
6396       bfd_reloc_status_type        r;
6397       arelent                      bfd_reloc;
6398       char                         sym_type;
6399       bfd_boolean                  unresolved_reloc = FALSE;
6400       char *error_message = NULL;
6401
6402       r_symndx = ELF32_R_SYM (rel->r_info);
6403       r_type   = ELF32_R_TYPE (rel->r_info);
6404       r_type   = arm_real_reloc_type (globals, r_type);
6405
6406       if (   r_type == R_ARM_GNU_VTENTRY
6407           || r_type == R_ARM_GNU_VTINHERIT)
6408         continue;
6409
6410       bfd_reloc.howto = elf32_arm_howto_from_type (r_type);
6411       howto = bfd_reloc.howto;
6412
6413       h = NULL;
6414       sym = NULL;
6415       sec = NULL;
6416
6417       if (r_symndx < symtab_hdr->sh_info)
6418         {
6419           sym = local_syms + r_symndx;
6420           sym_type = ELF32_ST_TYPE (sym->st_info);
6421           sec = local_sections[r_symndx];
6422           if (globals->use_rel)
6423             {
6424               relocation = (sec->output_section->vma
6425                             + sec->output_offset
6426                             + sym->st_value);
6427               if (!info->relocatable
6428                   && (sec->flags & SEC_MERGE)
6429                   && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
6430                 {
6431                   asection *msec;
6432                   bfd_vma addend, value;
6433
6434                   if (howto->rightshift)
6435                     {
6436                       (*_bfd_error_handler)
6437                         (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
6438                          input_bfd, input_section,
6439                          (long) rel->r_offset, howto->name);
6440                       return FALSE;
6441                     }
6442
6443                   value = bfd_get_32 (input_bfd, contents + rel->r_offset);
6444
6445                   /* Get the (signed) value from the instruction.  */
6446                   addend = value & howto->src_mask;
6447                   if (addend & ((howto->src_mask + 1) >> 1))
6448                     {
6449                       bfd_signed_vma mask;
6450
6451                       mask = -1;
6452                       mask &= ~ howto->src_mask;
6453                       addend |= mask;
6454                     }
6455                   msec = sec;
6456                   addend =
6457                     _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend)
6458                     - relocation;
6459                   addend += msec->output_section->vma + msec->output_offset;
6460                   value = (value & ~ howto->dst_mask) | (addend & howto->dst_mask);
6461                   bfd_put_32 (input_bfd, value, contents + rel->r_offset);
6462                 }
6463             }
6464           else
6465             relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
6466         }
6467       else
6468         {
6469           bfd_boolean warned;
6470
6471           RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
6472                                    r_symndx, symtab_hdr, sym_hashes,
6473                                    h, sec, relocation,
6474                                    unresolved_reloc, warned);
6475
6476           sym_type = h->type;
6477         }
6478
6479       if (sec != NULL && elf_discarded_section (sec))
6480         {
6481           /* For relocs against symbols from removed linkonce sections,
6482              or sections discarded by a linker script, we just want the
6483              section contents zeroed.  Avoid any special processing.  */
6484           _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
6485           rel->r_info = 0;
6486           rel->r_addend = 0;
6487           continue;
6488         }
6489
6490       if (info->relocatable)
6491         {
6492           /* This is a relocatable link.  We don't have to change
6493              anything, unless the reloc is against a section symbol,
6494              in which case we have to adjust according to where the
6495              section symbol winds up in the output section.  */
6496           if (sym != NULL && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
6497             {
6498               if (globals->use_rel)
6499                 arm_add_to_rel (input_bfd, contents + rel->r_offset,
6500                                 howto, (bfd_signed_vma) sec->output_offset);
6501               else
6502                 rel->r_addend += sec->output_offset;
6503             }
6504           continue;
6505         }
6506
6507       if (h != NULL)
6508         name = h->root.root.string;
6509       else
6510         {
6511           name = (bfd_elf_string_from_elf_section
6512                   (input_bfd, symtab_hdr->sh_link, sym->st_name));
6513           if (name == NULL || *name == '\0')
6514             name = bfd_section_name (input_bfd, sec);
6515         }
6516
6517       if (r_symndx != 0
6518           && r_type != R_ARM_NONE
6519           && (h == NULL
6520               || h->root.type == bfd_link_hash_defined
6521               || h->root.type == bfd_link_hash_defweak)
6522           && IS_ARM_TLS_RELOC (r_type) != (sym_type == STT_TLS))
6523         {
6524           (*_bfd_error_handler)
6525             ((sym_type == STT_TLS
6526               ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
6527               : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
6528              input_bfd,
6529              input_section,
6530              (long) rel->r_offset,
6531              howto->name,
6532              name);
6533         }
6534
6535       r = elf32_arm_final_link_relocate (howto, input_bfd, output_bfd,
6536                                          input_section, contents, rel,
6537                                          relocation, info, sec, name,
6538                                          (h ? ELF_ST_TYPE (h->type) :
6539                                           ELF_ST_TYPE (sym->st_info)), h,
6540                                          &unresolved_reloc, &error_message);
6541
6542       /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
6543          because such sections are not SEC_ALLOC and thus ld.so will
6544          not process them.  */
6545       if (unresolved_reloc
6546           && !((input_section->flags & SEC_DEBUGGING) != 0
6547                && h->def_dynamic))
6548         {
6549           (*_bfd_error_handler)
6550             (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
6551              input_bfd,
6552              input_section,
6553              (long) rel->r_offset,
6554              howto->name,
6555              h->root.root.string);
6556           return FALSE;
6557         }
6558
6559       if (r != bfd_reloc_ok)
6560         {
6561           switch (r)
6562             {
6563             case bfd_reloc_overflow:
6564               /* If the overflowing reloc was to an undefined symbol,
6565                  we have already printed one error message and there
6566                  is no point complaining again.  */
6567               if ((! h ||
6568                    h->root.type != bfd_link_hash_undefined)
6569                   && (!((*info->callbacks->reloc_overflow)
6570                         (info, (h ? &h->root : NULL), name, howto->name,
6571                          (bfd_vma) 0, input_bfd, input_section,
6572                          rel->r_offset))))
6573                   return FALSE;
6574               break;
6575
6576             case bfd_reloc_undefined:
6577               if (!((*info->callbacks->undefined_symbol)
6578                     (info, name, input_bfd, input_section,
6579                      rel->r_offset, TRUE)))
6580                 return FALSE;
6581               break;
6582
6583             case bfd_reloc_outofrange:
6584               error_message = _("out of range");
6585               goto common_error;
6586
6587             case bfd_reloc_notsupported:
6588               error_message = _("unsupported relocation");
6589               goto common_error;
6590
6591             case bfd_reloc_dangerous:
6592               /* error_message should already be set.  */
6593               goto common_error;
6594
6595             default:
6596               error_message = _("unknown error");
6597               /* fall through */
6598
6599             common_error:
6600               BFD_ASSERT (error_message != NULL);
6601               if (!((*info->callbacks->reloc_dangerous)
6602                     (info, error_message, input_bfd, input_section,
6603                      rel->r_offset)))
6604                 return FALSE;
6605               break;
6606             }
6607         }
6608     }
6609
6610   return TRUE;
6611 }
6612
6613 /* Set the right machine number.  */
6614
6615 static bfd_boolean
6616 elf32_arm_object_p (bfd *abfd)
6617 {
6618   unsigned int mach;
6619
6620   mach = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
6621
6622   if (mach != bfd_mach_arm_unknown)
6623     bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach);
6624
6625   else if (elf_elfheader (abfd)->e_flags & EF_ARM_MAVERICK_FLOAT)
6626     bfd_default_set_arch_mach (abfd, bfd_arch_arm, bfd_mach_arm_ep9312);
6627
6628   else
6629     bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach);
6630
6631   return TRUE;
6632 }
6633
6634 /* Function to keep ARM specific flags in the ELF header.  */
6635
6636 static bfd_boolean
6637 elf32_arm_set_private_flags (bfd *abfd, flagword flags)
6638 {
6639   if (elf_flags_init (abfd)
6640       && elf_elfheader (abfd)->e_flags != flags)
6641     {
6642       if (EF_ARM_EABI_VERSION (flags) == EF_ARM_EABI_UNKNOWN)
6643         {
6644           if (flags & EF_ARM_INTERWORK)
6645             (*_bfd_error_handler)
6646               (_("Warning: Not setting interworking flag of %B since it has already been specified as non-interworking"),
6647                abfd);
6648           else
6649             _bfd_error_handler
6650               (_("Warning: Clearing the interworking flag of %B due to outside request"),
6651                abfd);
6652         }
6653     }
6654   else
6655     {
6656       elf_elfheader (abfd)->e_flags = flags;
6657       elf_flags_init (abfd) = TRUE;
6658     }
6659
6660   return TRUE;
6661 }
6662
6663 /* Copy backend specific data from one object module to another.  */
6664
6665 static bfd_boolean
6666 elf32_arm_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
6667 {
6668   flagword in_flags;
6669   flagword out_flags;
6670
6671   if (   bfd_get_flavour (ibfd) != bfd_target_elf_flavour
6672       || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
6673     return TRUE;
6674
6675   in_flags  = elf_elfheader (ibfd)->e_flags;
6676   out_flags = elf_elfheader (obfd)->e_flags;
6677
6678   if (elf_flags_init (obfd)
6679       && EF_ARM_EABI_VERSION (out_flags) == EF_ARM_EABI_UNKNOWN
6680       && in_flags != out_flags)
6681     {
6682       /* Cannot mix APCS26 and APCS32 code.  */
6683       if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
6684         return FALSE;
6685
6686       /* Cannot mix float APCS and non-float APCS code.  */
6687       if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
6688         return FALSE;
6689
6690       /* If the src and dest have different interworking flags
6691          then turn off the interworking bit.  */
6692       if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
6693         {
6694           if (out_flags & EF_ARM_INTERWORK)
6695             _bfd_error_handler
6696               (_("Warning: Clearing the interworking flag of %B because non-interworking code in %B has been linked with it"),
6697                obfd, ibfd);
6698
6699           in_flags &= ~EF_ARM_INTERWORK;
6700         }
6701
6702       /* Likewise for PIC, though don't warn for this case.  */
6703       if ((in_flags & EF_ARM_PIC) != (out_flags & EF_ARM_PIC))
6704         in_flags &= ~EF_ARM_PIC;
6705     }
6706
6707   elf_elfheader (obfd)->e_flags = in_flags;
6708   elf_flags_init (obfd) = TRUE;
6709
6710   /* Also copy the EI_OSABI field.  */
6711   elf_elfheader (obfd)->e_ident[EI_OSABI] =
6712     elf_elfheader (ibfd)->e_ident[EI_OSABI];
6713
6714   /* Copy object attributes.  */
6715   _bfd_elf_copy_obj_attributes (ibfd, obfd);
6716
6717   return TRUE;
6718 }
6719
6720 /* Values for Tag_ABI_PCS_R9_use.  */
6721 enum
6722 {
6723   AEABI_R9_V6,
6724   AEABI_R9_SB,
6725   AEABI_R9_TLS,
6726   AEABI_R9_unused
6727 };
6728
6729 /* Values for Tag_ABI_PCS_RW_data.  */
6730 enum
6731 {
6732   AEABI_PCS_RW_data_absolute,
6733   AEABI_PCS_RW_data_PCrel,
6734   AEABI_PCS_RW_data_SBrel,
6735   AEABI_PCS_RW_data_unused
6736 };
6737
6738 /* Values for Tag_ABI_enum_size.  */
6739 enum
6740 {
6741   AEABI_enum_unused,
6742   AEABI_enum_short,
6743   AEABI_enum_wide,
6744   AEABI_enum_forced_wide
6745 };
6746
6747 /* Determine whether an object attribute tag takes an integer, a
6748    string or both.  */
6749 static int
6750 elf32_arm_obj_attrs_arg_type (int tag)
6751 {
6752   if (tag == Tag_compatibility)
6753     return 3;
6754   else if (tag == 4 || tag == 5)
6755     return 2;
6756   else if (tag < 32)
6757     return 1;
6758   else
6759     return (tag & 1) != 0 ? 2 : 1;
6760 }
6761
6762 /* Merge EABI object attributes from IBFD into OBFD.  Raise an error if there
6763    are conflicting attributes.  */
6764 static bfd_boolean
6765 elf32_arm_merge_eabi_attributes (bfd *ibfd, bfd *obfd)
6766 {
6767   obj_attribute *in_attr;
6768   obj_attribute *out_attr;
6769   obj_attribute_list *in_list;
6770   /* Some tags have 0 = don't care, 1 = strong requirement,
6771      2 = weak requirement.  */
6772   static const int order_312[3] = {3, 1, 2};
6773   int i;
6774
6775   if (!elf_known_obj_attributes_proc (obfd)[0].i)
6776     {
6777       /* This is the first object.  Copy the attributes.  */
6778       _bfd_elf_copy_obj_attributes (ibfd, obfd);
6779
6780       /* Use the Tag_null value to indicate the attributes have been
6781          initialized.  */
6782       elf_known_obj_attributes_proc (obfd)[0].i = 1;
6783
6784       return TRUE;
6785     }
6786
6787   in_attr = elf_known_obj_attributes_proc (ibfd);
6788   out_attr = elf_known_obj_attributes_proc (obfd);
6789   /* This needs to happen before Tag_ABI_FP_number_model is merged.  */
6790   if (in_attr[Tag_ABI_VFP_args].i != out_attr[Tag_ABI_VFP_args].i)
6791     {
6792       /* Ignore mismatches if teh object doesn't use floating point.  */
6793       if (out_attr[Tag_ABI_FP_number_model].i == 0)
6794         out_attr[Tag_ABI_VFP_args].i = in_attr[Tag_ABI_VFP_args].i;
6795       else if (in_attr[Tag_ABI_FP_number_model].i != 0)
6796         {
6797           bfd *hasbfd, *hasnotbfd;
6798           
6799           if (in_attr[Tag_ABI_VFP_args].i)
6800             {
6801               hasbfd = ibfd;
6802               hasnotbfd = obfd;
6803             }
6804           else
6805             {
6806               hasbfd = obfd;
6807               hasnotbfd = ibfd;
6808             }
6809
6810           _bfd_error_handler
6811             (_("ERROR: %B uses VFP register arguments, %B does not"),
6812                 hasbfd, hasnotbfd);
6813           return FALSE;
6814         }
6815     }
6816
6817   for (i = 4; i < NUM_KNOWN_OBJ_ATTRIBUTES; i++)
6818     {
6819       if (out_attr[i].type == 0)
6820         out_attr[i].type = in_attr[i].type;
6821
6822       /* Merge this attribute with existing attributes.  */
6823       switch (i)
6824         {
6825         case Tag_CPU_raw_name:
6826         case Tag_CPU_name:
6827           /* Use whichever has the greatest architecture requirements.  We
6828              won't necessarily have both the above tags, so make sure input
6829              name is non-NULL.  */
6830           if (in_attr[Tag_CPU_arch].i > out_attr[Tag_CPU_arch].i
6831               && in_attr[i].s)
6832             out_attr[i].s = _bfd_elf_attr_strdup (obfd, in_attr[i].s);
6833           break;
6834
6835         case Tag_ABI_optimization_goals:
6836         case Tag_ABI_FP_optimization_goals:
6837           /* Use the first value seen.  */
6838           break;
6839
6840         case Tag_CPU_arch:
6841         case Tag_ARM_ISA_use:
6842         case Tag_THUMB_ISA_use:
6843         case Tag_VFP_arch:
6844         case Tag_WMMX_arch:
6845         case Tag_NEON_arch:
6846           /* ??? Do NEON and WMMX conflict?  */
6847         case Tag_ABI_FP_rounding:
6848         case Tag_ABI_FP_denormal:
6849         case Tag_ABI_FP_exceptions:
6850         case Tag_ABI_FP_user_exceptions:
6851         case Tag_ABI_FP_number_model:
6852         case Tag_ABI_align8_preserved:
6853         case Tag_ABI_HardFP_use:
6854         case Tag_CPU_unaligned_access:
6855         case Tag_FP_HP_extension:
6856           /* Use the largest value specified.  */
6857           if (in_attr[i].i > out_attr[i].i)
6858             out_attr[i].i = in_attr[i].i;
6859           break;
6860
6861         case Tag_CPU_arch_profile:
6862           /* Warn if conflicting architecture profiles used.  */
6863           if (out_attr[i].i && in_attr[i].i && in_attr[i].i != out_attr[i].i)
6864             {
6865               _bfd_error_handler
6866                 (_("ERROR: %B: Conflicting architecture profiles %c/%c"),
6867                  ibfd, in_attr[i].i, out_attr[i].i);
6868               return FALSE;
6869             }
6870           if (in_attr[i].i)
6871             out_attr[i].i = in_attr[i].i;
6872           break;
6873         case Tag_PCS_config:
6874           if (out_attr[i].i == 0)
6875             out_attr[i].i = in_attr[i].i;
6876           else if (in_attr[i].i != 0 && out_attr[i].i != 0)
6877             {
6878               /* It's sometimes ok to mix different configs, so this is only
6879                  a warning.  */
6880               _bfd_error_handler
6881                 (_("Warning: %B: Conflicting platform configuration"), ibfd);
6882             }
6883           break;
6884         case Tag_ABI_PCS_R9_use:
6885           if (in_attr[i].i != out_attr[i].i
6886               && out_attr[i].i != AEABI_R9_unused
6887               && in_attr[i].i != AEABI_R9_unused)
6888             {
6889               _bfd_error_handler
6890                 (_("ERROR: %B: Conflicting use of R9"), ibfd);
6891               return FALSE;
6892             }
6893           if (out_attr[i].i == AEABI_R9_unused)
6894             out_attr[i].i = in_attr[i].i;
6895           break;
6896         case Tag_ABI_PCS_RW_data:
6897           if (in_attr[i].i == AEABI_PCS_RW_data_SBrel
6898               && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_SB
6899               && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_unused)
6900             {
6901               _bfd_error_handler
6902                 (_("ERROR: %B: SB relative addressing conflicts with use of R9"),
6903                  ibfd);
6904               return FALSE;
6905             }
6906           /* Use the smallest value specified.  */
6907           if (in_attr[i].i < out_attr[i].i)
6908             out_attr[i].i = in_attr[i].i;
6909           break;
6910         case Tag_ABI_PCS_RO_data:
6911           /* Use the smallest value specified.  */
6912           if (in_attr[i].i < out_attr[i].i)
6913             out_attr[i].i = in_attr[i].i;
6914           break;
6915         case Tag_ABI_PCS_GOT_use:
6916           if (in_attr[i].i > 2 || out_attr[i].i > 2
6917               || order_312[in_attr[i].i] < order_312[out_attr[i].i])
6918             out_attr[i].i = in_attr[i].i;
6919           break;
6920         case Tag_ABI_PCS_wchar_t:
6921           if (out_attr[i].i && in_attr[i].i && out_attr[i].i != in_attr[i].i)
6922             {
6923               _bfd_error_handler
6924                 (_("ERROR: %B: Conflicting definitions of wchar_t"), ibfd);
6925               return FALSE;
6926             }
6927           if (in_attr[i].i)
6928             out_attr[i].i = in_attr[i].i;
6929           break;
6930         case Tag_ABI_align8_needed:
6931           /* ??? Check against Tag_ABI_align8_preserved.  */
6932           if (in_attr[i].i > 2 || out_attr[i].i > 2
6933               || order_312[in_attr[i].i] < order_312[out_attr[i].i])
6934             out_attr[i].i = in_attr[i].i;
6935           break;
6936         case Tag_ABI_enum_size:
6937           if (in_attr[i].i != AEABI_enum_unused)
6938             {
6939               if (out_attr[i].i == AEABI_enum_unused
6940                   || out_attr[i].i == AEABI_enum_forced_wide)
6941                 {
6942                   /* The existing object is compatible with anything.
6943                      Use whatever requirements the new object has.  */
6944                   out_attr[i].i = in_attr[i].i;
6945                 }
6946               else if (in_attr[i].i != AEABI_enum_forced_wide
6947                        && out_attr[i].i != in_attr[i].i
6948                        && !elf32_arm_tdata (obfd)->no_enum_size_warning)
6949                 {
6950                   const char *aeabi_enum_names[] =
6951                     { "", "variable-size", "32-bit", "" };
6952                   _bfd_error_handler
6953                     (_("warning: %B uses %s enums yet the output is to use %s enums; use of enum values across objects may fail"),
6954                      ibfd, aeabi_enum_names[in_attr[i].i],
6955                      aeabi_enum_names[out_attr[i].i]);
6956                 }
6957             }
6958           break;
6959         case Tag_ABI_VFP_args:
6960           /* Aready done.  */
6961           break;
6962         case Tag_ABI_WMMX_args:
6963           if (in_attr[i].i != out_attr[i].i)
6964             {
6965               _bfd_error_handler
6966                 (_("ERROR: %B uses iWMMXt register arguments, %B does not"),
6967                  ibfd, obfd);
6968               return FALSE;
6969             }
6970           break;
6971         default: /* All known attributes should be explicitly covered.   */
6972           /* XXX Not now */
6973           /* abort (); */
6974           break;
6975         }
6976     }
6977
6978   /* Merge Tag_compatibility attributes and any common GNU ones.  */
6979   _bfd_elf_merge_object_attributes (ibfd, obfd);
6980
6981   /* Check for any attributes not known on ARM.  */
6982   in_list = elf_other_obj_attributes_proc (ibfd);
6983   while (in_list && in_list->tag == Tag_compatibility)
6984     in_list = in_list->next;
6985
6986   for (; in_list; in_list = in_list->next)
6987     {
6988       if ((in_list->tag & 128) < 64
6989           && in_list->tag != Tag_Virtualization_use)
6990         {
6991           _bfd_error_handler
6992             (_("Warning: %B: Unknown EABI object attribute %d"),
6993              ibfd, in_list->tag);
6994           break;
6995         }
6996     }
6997   return TRUE;
6998 }
6999
7000
7001 /* Return TRUE if the two EABI versions are incompatible.  */
7002
7003 static bfd_boolean
7004 elf32_arm_versions_compatible (unsigned iver, unsigned over)
7005 {
7006   /* v4 and v5 are the same spec before and after it was released,
7007      so allow mixing them.  */
7008   if ((iver == EF_ARM_EABI_VER4 && over == EF_ARM_EABI_VER5)
7009       || (iver == EF_ARM_EABI_VER5 && over == EF_ARM_EABI_VER4))
7010     return TRUE;
7011
7012   return (iver == over);
7013 }
7014
7015 /* Merge backend specific data from an object file to the output
7016    object file when linking.  */
7017
7018 static bfd_boolean
7019 elf32_arm_merge_private_bfd_data (bfd * ibfd, bfd * obfd)
7020 {
7021   flagword out_flags;
7022   flagword in_flags;
7023   bfd_boolean flags_compatible = TRUE;
7024   asection *sec;
7025
7026   /* Check if we have the same endianess.  */
7027   if (! _bfd_generic_verify_endian_match (ibfd, obfd))
7028     return FALSE;
7029
7030   if (   bfd_get_flavour (ibfd) != bfd_target_elf_flavour
7031       || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
7032     return TRUE;
7033
7034   if (!elf32_arm_merge_eabi_attributes (ibfd, obfd))
7035     return FALSE;
7036
7037   /* The input BFD must have had its flags initialised.  */
7038   /* The following seems bogus to me -- The flags are initialized in
7039      the assembler but I don't think an elf_flags_init field is
7040      written into the object.  */
7041   /* BFD_ASSERT (elf_flags_init (ibfd)); */
7042
7043   in_flags  = elf_elfheader (ibfd)->e_flags;
7044   out_flags = elf_elfheader (obfd)->e_flags;
7045
7046   if (!elf_flags_init (obfd))
7047     {
7048       /* If the input is the default architecture and had the default
7049          flags then do not bother setting the flags for the output
7050          architecture, instead allow future merges to do this.  If no
7051          future merges ever set these flags then they will retain their
7052          uninitialised values, which surprise surprise, correspond
7053          to the default values.  */
7054       if (bfd_get_arch_info (ibfd)->the_default
7055           && elf_elfheader (ibfd)->e_flags == 0)
7056         return TRUE;
7057
7058       elf_flags_init (obfd) = TRUE;
7059       elf_elfheader (obfd)->e_flags = in_flags;
7060
7061       if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
7062           && bfd_get_arch_info (obfd)->the_default)
7063         return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd));
7064
7065       return TRUE;
7066     }
7067
7068   /* Determine what should happen if the input ARM architecture
7069      does not match the output ARM architecture.  */
7070   if (! bfd_arm_merge_machines (ibfd, obfd))
7071     return FALSE;
7072
7073   /* Identical flags must be compatible.  */
7074   if (in_flags == out_flags)
7075     return TRUE;
7076
7077   /* Check to see if the input BFD actually contains any sections.  If
7078      not, its flags may not have been initialised either, but it
7079      cannot actually cause any incompatiblity.  Do not short-circuit
7080      dynamic objects; their section list may be emptied by
7081     elf_link_add_object_symbols.
7082
7083     Also check to see if there are no code sections in the input.
7084     In this case there is no need to check for code specific flags.
7085     XXX - do we need to worry about floating-point format compatability
7086     in data sections ?  */
7087   if (!(ibfd->flags & DYNAMIC))
7088     {
7089       bfd_boolean null_input_bfd = TRUE;
7090       bfd_boolean only_data_sections = TRUE;
7091
7092       for (sec = ibfd->sections; sec != NULL; sec = sec->next)
7093         {
7094           /* Ignore synthetic glue sections.  */
7095           if (strcmp (sec->name, ".glue_7")
7096               && strcmp (sec->name, ".glue_7t"))
7097             {
7098               if ((bfd_get_section_flags (ibfd, sec)
7099                    & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
7100                   == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
7101                 only_data_sections = FALSE;
7102
7103               null_input_bfd = FALSE;
7104               break;
7105             }
7106         }
7107
7108       if (null_input_bfd || only_data_sections)
7109         return TRUE;
7110     }
7111
7112   /* Complain about various flag mismatches.  */
7113   if (!elf32_arm_versions_compatible (EF_ARM_EABI_VERSION (in_flags),
7114                                       EF_ARM_EABI_VERSION (out_flags)))
7115     {
7116       _bfd_error_handler
7117         (_("ERROR: Source object %B has EABI version %d, but target %B has EABI version %d"),
7118          ibfd, obfd,
7119          (in_flags & EF_ARM_EABIMASK) >> 24,
7120          (out_flags & EF_ARM_EABIMASK) >> 24);
7121       return FALSE;
7122     }
7123
7124   /* Not sure what needs to be checked for EABI versions >= 1.  */
7125   /* VxWorks libraries do not use these flags.  */
7126   if (get_elf_backend_data (obfd) != &elf32_arm_vxworks_bed
7127       && get_elf_backend_data (ibfd) != &elf32_arm_vxworks_bed
7128       && EF_ARM_EABI_VERSION (in_flags) == EF_ARM_EABI_UNKNOWN)
7129     {
7130       if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
7131         {
7132           _bfd_error_handler
7133             (_("ERROR: %B is compiled for APCS-%d, whereas target %B uses APCS-%d"),
7134              ibfd, obfd,
7135              in_flags & EF_ARM_APCS_26 ? 26 : 32,
7136              out_flags & EF_ARM_APCS_26 ? 26 : 32);
7137           flags_compatible = FALSE;
7138         }
7139
7140       if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
7141         {
7142           if (in_flags & EF_ARM_APCS_FLOAT)
7143             _bfd_error_handler
7144               (_("ERROR: %B passes floats in float registers, whereas %B passes them in integer registers"),
7145                ibfd, obfd);
7146           else
7147             _bfd_error_handler
7148               (_("ERROR: %B passes floats in integer registers, whereas %B passes them in float registers"),
7149                ibfd, obfd);
7150
7151           flags_compatible = FALSE;
7152         }
7153
7154       if ((in_flags & EF_ARM_VFP_FLOAT) != (out_flags & EF_ARM_VFP_FLOAT))
7155         {
7156           if (in_flags & EF_ARM_VFP_FLOAT)
7157             _bfd_error_handler
7158               (_("ERROR: %B uses VFP instructions, whereas %B does not"),
7159                ibfd, obfd);
7160           else
7161             _bfd_error_handler
7162               (_("ERROR: %B uses FPA instructions, whereas %B does not"),
7163                ibfd, obfd);
7164
7165           flags_compatible = FALSE;
7166         }
7167
7168       if ((in_flags & EF_ARM_MAVERICK_FLOAT) != (out_flags & EF_ARM_MAVERICK_FLOAT))
7169         {
7170           if (in_flags & EF_ARM_MAVERICK_FLOAT)
7171             _bfd_error_handler
7172               (_("ERROR: %B uses Maverick instructions, whereas %B does not"),
7173                ibfd, obfd);
7174           else
7175             _bfd_error_handler
7176               (_("ERROR: %B does not use Maverick instructions, whereas %B does"),
7177                ibfd, obfd);
7178
7179           flags_compatible = FALSE;
7180         }
7181
7182 #ifdef EF_ARM_SOFT_FLOAT
7183       if ((in_flags & EF_ARM_SOFT_FLOAT) != (out_flags & EF_ARM_SOFT_FLOAT))
7184         {
7185           /* We can allow interworking between code that is VFP format
7186              layout, and uses either soft float or integer regs for
7187              passing floating point arguments and results.  We already
7188              know that the APCS_FLOAT flags match; similarly for VFP
7189              flags.  */
7190           if ((in_flags & EF_ARM_APCS_FLOAT) != 0
7191               || (in_flags & EF_ARM_VFP_FLOAT) == 0)
7192             {
7193               if (in_flags & EF_ARM_SOFT_FLOAT)
7194                 _bfd_error_handler
7195                   (_("ERROR: %B uses software FP, whereas %B uses hardware FP"),
7196                    ibfd, obfd);
7197               else
7198                 _bfd_error_handler
7199                   (_("ERROR: %B uses hardware FP, whereas %B uses software FP"),
7200                    ibfd, obfd);
7201
7202               flags_compatible = FALSE;
7203             }
7204         }
7205 #endif
7206
7207       /* Interworking mismatch is only a warning.  */
7208       if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
7209         {
7210           if (in_flags & EF_ARM_INTERWORK)
7211             {
7212               _bfd_error_handler
7213                 (_("Warning: %B supports interworking, whereas %B does not"),
7214                  ibfd, obfd);
7215             }
7216           else
7217             {
7218               _bfd_error_handler
7219                 (_("Warning: %B does not support interworking, whereas %B does"),
7220                  ibfd, obfd);
7221             }
7222         }
7223     }
7224
7225   return flags_compatible;
7226 }
7227
7228 /* Display the flags field.  */
7229
7230 static bfd_boolean
7231 elf32_arm_print_private_bfd_data (bfd *abfd, void * ptr)
7232 {
7233   FILE * file = (FILE *) ptr;
7234   unsigned long flags;
7235
7236   BFD_ASSERT (abfd != NULL && ptr != NULL);
7237
7238   /* Print normal ELF private data.  */
7239   _bfd_elf_print_private_bfd_data (abfd, ptr);
7240
7241   flags = elf_elfheader (abfd)->e_flags;
7242   /* Ignore init flag - it may not be set, despite the flags field
7243      containing valid data.  */
7244
7245   /* xgettext:c-format */
7246   fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
7247
7248   switch (EF_ARM_EABI_VERSION (flags))
7249     {
7250     case EF_ARM_EABI_UNKNOWN:
7251       /* The following flag bits are GNU extensions and not part of the
7252          official ARM ELF extended ABI.  Hence they are only decoded if
7253          the EABI version is not set.  */
7254       if (flags & EF_ARM_INTERWORK)
7255         fprintf (file, _(" [interworking enabled]"));
7256
7257       if (flags & EF_ARM_APCS_26)
7258         fprintf (file, " [APCS-26]");
7259       else
7260         fprintf (file, " [APCS-32]");
7261
7262       if (flags & EF_ARM_VFP_FLOAT)
7263         fprintf (file, _(" [VFP float format]"));
7264       else if (flags & EF_ARM_MAVERICK_FLOAT)
7265         fprintf (file, _(" [Maverick float format]"));
7266       else
7267         fprintf (file, _(" [FPA float format]"));
7268
7269       if (flags & EF_ARM_APCS_FLOAT)
7270         fprintf (file, _(" [floats passed in float registers]"));
7271
7272       if (flags & EF_ARM_PIC)
7273         fprintf (file, _(" [position independent]"));
7274
7275       if (flags & EF_ARM_NEW_ABI)
7276         fprintf (file, _(" [new ABI]"));
7277
7278       if (flags & EF_ARM_OLD_ABI)
7279         fprintf (file, _(" [old ABI]"));
7280
7281       if (flags & EF_ARM_SOFT_FLOAT)
7282         fprintf (file, _(" [software FP]"));
7283
7284       flags &= ~(EF_ARM_INTERWORK | EF_ARM_APCS_26 | EF_ARM_APCS_FLOAT
7285                  | EF_ARM_PIC | EF_ARM_NEW_ABI | EF_ARM_OLD_ABI
7286                  | EF_ARM_SOFT_FLOAT | EF_ARM_VFP_FLOAT
7287                  | EF_ARM_MAVERICK_FLOAT);
7288       break;
7289
7290     case EF_ARM_EABI_VER1:
7291       fprintf (file, _(" [Version1 EABI]"));
7292
7293       if (flags & EF_ARM_SYMSARESORTED)
7294         fprintf (file, _(" [sorted symbol table]"));
7295       else
7296         fprintf (file, _(" [unsorted symbol table]"));
7297
7298       flags &= ~ EF_ARM_SYMSARESORTED;
7299       break;
7300
7301     case EF_ARM_EABI_VER2:
7302       fprintf (file, _(" [Version2 EABI]"));
7303
7304       if (flags & EF_ARM_SYMSARESORTED)
7305         fprintf (file, _(" [sorted symbol table]"));
7306       else
7307         fprintf (file, _(" [unsorted symbol table]"));
7308
7309       if (flags & EF_ARM_DYNSYMSUSESEGIDX)
7310         fprintf (file, _(" [dynamic symbols use segment index]"));
7311
7312       if (flags & EF_ARM_MAPSYMSFIRST)
7313         fprintf (file, _(" [mapping symbols precede others]"));
7314
7315       flags &= ~(EF_ARM_SYMSARESORTED | EF_ARM_DYNSYMSUSESEGIDX
7316                  | EF_ARM_MAPSYMSFIRST);
7317       break;
7318
7319     case EF_ARM_EABI_VER3:
7320       fprintf (file, _(" [Version3 EABI]"));
7321       break;
7322
7323     case EF_ARM_EABI_VER4:
7324       fprintf (file, _(" [Version4 EABI]"));
7325       goto eabi;
7326
7327     case EF_ARM_EABI_VER5:
7328       fprintf (file, _(" [Version5 EABI]"));
7329     eabi:
7330       if (flags & EF_ARM_BE8)
7331         fprintf (file, _(" [BE8]"));
7332
7333       if (flags & EF_ARM_LE8)
7334         fprintf (file, _(" [LE8]"));
7335
7336       flags &= ~(EF_ARM_LE8 | EF_ARM_BE8);
7337       break;
7338
7339     default:
7340       fprintf (file, _(" <EABI version unrecognised>"));
7341       break;
7342     }
7343
7344   flags &= ~ EF_ARM_EABIMASK;
7345
7346   if (flags & EF_ARM_RELEXEC)
7347     fprintf (file, _(" [relocatable executable]"));
7348
7349   if (flags & EF_ARM_HASENTRY)
7350     fprintf (file, _(" [has entry point]"));
7351
7352   flags &= ~ (EF_ARM_RELEXEC | EF_ARM_HASENTRY);
7353
7354   if (flags)
7355     fprintf (file, _("<Unrecognised flag bits set>"));
7356
7357   fputc ('\n', file);
7358
7359   return TRUE;
7360 }
7361
7362 static int
7363 elf32_arm_get_symbol_type (Elf_Internal_Sym * elf_sym, int type)
7364 {
7365   switch (ELF_ST_TYPE (elf_sym->st_info))
7366     {
7367     case STT_ARM_TFUNC:
7368       return ELF_ST_TYPE (elf_sym->st_info);
7369
7370     case STT_ARM_16BIT:
7371       /* If the symbol is not an object, return the STT_ARM_16BIT flag.
7372          This allows us to distinguish between data used by Thumb instructions
7373          and non-data (which is probably code) inside Thumb regions of an
7374          executable.  */
7375       if (type != STT_OBJECT && type != STT_TLS)
7376         return ELF_ST_TYPE (elf_sym->st_info);
7377       break;
7378
7379     default:
7380       break;
7381     }
7382
7383   return type;
7384 }
7385
7386 static asection *
7387 elf32_arm_gc_mark_hook (asection *sec,
7388                         struct bfd_link_info *info,
7389                         Elf_Internal_Rela *rel,
7390                         struct elf_link_hash_entry *h,
7391                         Elf_Internal_Sym *sym)
7392 {
7393   if (h != NULL)
7394     switch (ELF32_R_TYPE (rel->r_info))
7395       {
7396       case R_ARM_GNU_VTINHERIT:
7397       case R_ARM_GNU_VTENTRY:
7398         return NULL;
7399       }
7400
7401   return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
7402 }
7403
7404 /* Update the got entry reference counts for the section being removed.  */
7405
7406 static bfd_boolean
7407 elf32_arm_gc_sweep_hook (bfd *                     abfd,
7408                          struct bfd_link_info *    info,
7409                          asection *                sec,
7410                          const Elf_Internal_Rela * relocs)
7411 {
7412   Elf_Internal_Shdr *symtab_hdr;
7413   struct elf_link_hash_entry **sym_hashes;
7414   bfd_signed_vma *local_got_refcounts;
7415   const Elf_Internal_Rela *rel, *relend;
7416   struct elf32_arm_link_hash_table * globals;
7417
7418   globals = elf32_arm_hash_table (info);
7419
7420   elf_section_data (sec)->local_dynrel = NULL;
7421
7422   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
7423   sym_hashes = elf_sym_hashes (abfd);
7424   local_got_refcounts = elf_local_got_refcounts (abfd);
7425
7426   relend = relocs + sec->reloc_count;
7427   for (rel = relocs; rel < relend; rel++)
7428     {
7429       unsigned long r_symndx;
7430       struct elf_link_hash_entry *h = NULL;
7431       int r_type;
7432
7433       r_symndx = ELF32_R_SYM (rel->r_info);
7434       if (r_symndx >= symtab_hdr->sh_info)
7435         {
7436           h = sym_hashes[r_symndx - symtab_hdr->sh_info];
7437           while (h->root.type == bfd_link_hash_indirect
7438                  || h->root.type == bfd_link_hash_warning)
7439             h = (struct elf_link_hash_entry *) h->root.u.i.link;
7440         }
7441
7442       r_type = ELF32_R_TYPE (rel->r_info);
7443       r_type = arm_real_reloc_type (globals, r_type);
7444       switch (r_type)
7445         {
7446         case R_ARM_GOT32:
7447         case R_ARM_GOT_PREL:
7448         case R_ARM_TLS_GD32:
7449         case R_ARM_TLS_IE32:
7450           if (h != NULL)
7451             {
7452               if (h->got.refcount > 0)
7453                 h->got.refcount -= 1;
7454             }
7455           else if (local_got_refcounts != NULL)
7456             {
7457               if (local_got_refcounts[r_symndx] > 0)
7458                 local_got_refcounts[r_symndx] -= 1;
7459             }
7460           break;
7461
7462         case R_ARM_TLS_LDM32:
7463           elf32_arm_hash_table (info)->tls_ldm_got.refcount -= 1;
7464           break;
7465
7466         case R_ARM_ABS32:
7467         case R_ARM_ABS32_NOI:
7468         case R_ARM_REL32:
7469         case R_ARM_REL32_NOI:
7470         case R_ARM_PC24:
7471         case R_ARM_PLT32:
7472         case R_ARM_CALL:
7473         case R_ARM_JUMP24:
7474         case R_ARM_PREL31:
7475         case R_ARM_THM_CALL:
7476         case R_ARM_MOVW_ABS_NC:
7477         case R_ARM_MOVT_ABS:
7478         case R_ARM_MOVW_PREL_NC:
7479         case R_ARM_MOVT_PREL:
7480         case R_ARM_THM_MOVW_ABS_NC:
7481         case R_ARM_THM_MOVT_ABS:
7482         case R_ARM_THM_MOVW_PREL_NC:
7483         case R_ARM_THM_MOVT_PREL:
7484           /* Should the interworking branches be here also?  */
7485
7486           if (h != NULL)
7487             {
7488               struct elf32_arm_link_hash_entry *eh;
7489               struct elf32_arm_relocs_copied **pp;
7490               struct elf32_arm_relocs_copied *p;
7491
7492               eh = (struct elf32_arm_link_hash_entry *) h;
7493
7494               if (h->plt.refcount > 0)
7495                 {
7496                   h->plt.refcount -= 1;
7497                   if (ELF32_R_TYPE (rel->r_info) == R_ARM_THM_CALL)
7498                     eh->plt_thumb_refcount--;
7499                 }
7500
7501               if (r_type == R_ARM_ABS32
7502                   || r_type == R_ARM_REL32
7503                   || r_type == R_ARM_ABS32_NOI
7504                   || r_type == R_ARM_REL32_NOI)
7505                 {
7506                   for (pp = &eh->relocs_copied; (p = *pp) != NULL;
7507                        pp = &p->next)
7508                   if (p->section == sec)
7509                     {
7510                       p->count -= 1;
7511                       if (ELF32_R_TYPE (rel->r_info) == R_ARM_REL32
7512                           || ELF32_R_TYPE (rel->r_info) == R_ARM_REL32_NOI)
7513                         p->pc_count -= 1;
7514                       if (p->count == 0)
7515                         *pp = p->next;
7516                       break;
7517                     }
7518                 }
7519             }
7520           break;
7521
7522         default:
7523           break;
7524         }
7525     }
7526
7527   return TRUE;
7528 }
7529
7530 /* Look through the relocs for a section during the first phase.  */
7531
7532 static bfd_boolean
7533 elf32_arm_check_relocs (bfd *abfd, struct bfd_link_info *info,
7534                         asection *sec, const Elf_Internal_Rela *relocs)
7535 {
7536   Elf_Internal_Shdr *symtab_hdr;
7537   struct elf_link_hash_entry **sym_hashes;
7538   struct elf_link_hash_entry **sym_hashes_end;
7539   const Elf_Internal_Rela *rel;
7540   const Elf_Internal_Rela *rel_end;
7541   bfd *dynobj;
7542   asection *sreloc;
7543   bfd_vma *local_got_offsets;
7544   struct elf32_arm_link_hash_table *htab;
7545
7546   if (info->relocatable)
7547     return TRUE;
7548
7549   htab = elf32_arm_hash_table (info);
7550   sreloc = NULL;
7551
7552   /* Create dynamic sections for relocatable executables so that we can
7553      copy relocations.  */
7554   if (htab->root.is_relocatable_executable
7555       && ! htab->root.dynamic_sections_created)
7556     {
7557       if (! _bfd_elf_link_create_dynamic_sections (abfd, info))
7558         return FALSE;
7559     }
7560
7561   dynobj = elf_hash_table (info)->dynobj;
7562   local_got_offsets = elf_local_got_offsets (abfd);
7563
7564   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
7565   sym_hashes = elf_sym_hashes (abfd);
7566   sym_hashes_end = sym_hashes
7567     + symtab_hdr->sh_size / sizeof (Elf32_External_Sym);
7568
7569   if (!elf_bad_symtab (abfd))
7570     sym_hashes_end -= symtab_hdr->sh_info;
7571
7572   rel_end = relocs + sec->reloc_count;
7573   for (rel = relocs; rel < rel_end; rel++)
7574     {
7575       struct elf_link_hash_entry *h;
7576       struct elf32_arm_link_hash_entry *eh;
7577       unsigned long r_symndx;
7578       int r_type;
7579
7580       r_symndx = ELF32_R_SYM (rel->r_info);
7581       r_type = ELF32_R_TYPE (rel->r_info);
7582       r_type = arm_real_reloc_type (htab, r_type);
7583
7584       if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
7585         {
7586           (*_bfd_error_handler) (_("%B: bad symbol index: %d"), abfd,
7587                                  r_symndx);
7588           return FALSE;
7589         }
7590
7591       if (r_symndx < symtab_hdr->sh_info)
7592         h = NULL;
7593       else
7594         {
7595           h = sym_hashes[r_symndx - symtab_hdr->sh_info];
7596           while (h->root.type == bfd_link_hash_indirect
7597                  || h->root.type == bfd_link_hash_warning)
7598             h = (struct elf_link_hash_entry *) h->root.u.i.link;
7599         }
7600
7601       eh = (struct elf32_arm_link_hash_entry *) h;
7602
7603       switch (r_type)
7604         {
7605           case R_ARM_GOT32:
7606           case R_ARM_GOT_PREL:
7607           case R_ARM_TLS_GD32:
7608           case R_ARM_TLS_IE32:
7609             /* This symbol requires a global offset table entry.  */
7610             {
7611               int tls_type, old_tls_type;
7612
7613               switch (r_type)
7614                 {
7615                 case R_ARM_TLS_GD32: tls_type = GOT_TLS_GD; break;
7616                 case R_ARM_TLS_IE32: tls_type = GOT_TLS_IE; break;
7617                 default: tls_type = GOT_NORMAL; break;
7618                 }
7619
7620               if (h != NULL)
7621                 {
7622                   h->got.refcount++;
7623                   old_tls_type = elf32_arm_hash_entry (h)->tls_type;
7624                 }
7625               else
7626                 {
7627                   bfd_signed_vma *local_got_refcounts;
7628
7629                   /* This is a global offset table entry for a local symbol.  */
7630                   local_got_refcounts = elf_local_got_refcounts (abfd);
7631                   if (local_got_refcounts == NULL)
7632                     {
7633                       bfd_size_type size;
7634                       
7635                       size = symtab_hdr->sh_info;
7636                       size *= (sizeof (bfd_signed_vma) + sizeof(char));
7637                       local_got_refcounts = bfd_zalloc (abfd, size);
7638                       if (local_got_refcounts == NULL)
7639                         return FALSE;
7640                       elf_local_got_refcounts (abfd) = local_got_refcounts;
7641                       elf32_arm_local_got_tls_type (abfd)
7642                         = (char *) (local_got_refcounts + symtab_hdr->sh_info);
7643                     }
7644                   local_got_refcounts[r_symndx] += 1;
7645                   old_tls_type = elf32_arm_local_got_tls_type (abfd) [r_symndx];
7646                 }
7647
7648               /* We will already have issued an error message if there is a
7649                  TLS / non-TLS mismatch, based on the symbol type.  We don't
7650                  support any linker relaxations.  So just combine any TLS
7651                  types needed.  */
7652               if (old_tls_type != GOT_UNKNOWN && old_tls_type != GOT_NORMAL
7653                   && tls_type != GOT_NORMAL)
7654                 tls_type |= old_tls_type;
7655
7656               if (old_tls_type != tls_type)
7657                 {
7658                   if (h != NULL)
7659                     elf32_arm_hash_entry (h)->tls_type = tls_type;
7660                   else
7661                     elf32_arm_local_got_tls_type (abfd) [r_symndx] = tls_type;
7662                 }
7663             }
7664             /* Fall through */
7665
7666           case R_ARM_TLS_LDM32:
7667             if (r_type == R_ARM_TLS_LDM32)
7668                 htab->tls_ldm_got.refcount++;
7669             /* Fall through */
7670
7671           case R_ARM_GOTOFF32:
7672           case R_ARM_GOTPC:
7673             if (htab->sgot == NULL)
7674               {
7675                 if (htab->root.dynobj == NULL)
7676                   htab->root.dynobj = abfd;
7677                 if (!create_got_section (htab->root.dynobj, info))
7678                   return FALSE;
7679               }
7680             break;
7681
7682           case R_ARM_ABS12:
7683             /* VxWorks uses dynamic R_ARM_ABS12 relocations for
7684                ldr __GOTT_INDEX__ offsets.  */
7685             if (!htab->vxworks_p)
7686               break;
7687             /* Fall through */
7688
7689           case R_ARM_ABS32:
7690           case R_ARM_ABS32_NOI:
7691           case R_ARM_REL32:
7692           case R_ARM_REL32_NOI:
7693           case R_ARM_PC24:
7694           case R_ARM_PLT32:
7695           case R_ARM_CALL:
7696           case R_ARM_JUMP24:
7697           case R_ARM_PREL31:
7698           case R_ARM_THM_CALL:
7699           case R_ARM_MOVW_ABS_NC:
7700           case R_ARM_MOVT_ABS:
7701           case R_ARM_MOVW_PREL_NC:
7702           case R_ARM_MOVT_PREL:
7703           case R_ARM_THM_MOVW_ABS_NC:
7704           case R_ARM_THM_MOVT_ABS:
7705           case R_ARM_THM_MOVW_PREL_NC:
7706           case R_ARM_THM_MOVT_PREL:
7707             /* Should the interworking branches be listed here?  */
7708             if (h != NULL)
7709               {
7710                 /* If this reloc is in a read-only section, we might
7711                    need a copy reloc.  We can't check reliably at this
7712                    stage whether the section is read-only, as input
7713                    sections have not yet been mapped to output sections.
7714                    Tentatively set the flag for now, and correct in
7715                    adjust_dynamic_symbol.  */
7716                 if (!info->shared)
7717                   h->non_got_ref = 1;
7718
7719                 /* We may need a .plt entry if the function this reloc
7720                    refers to is in a different object.  We can't tell for
7721                    sure yet, because something later might force the
7722                    symbol local.  */
7723                 switch (r_type)
7724                   {
7725                     case R_ARM_ABS12:
7726                     case R_ARM_ABS32:
7727                     case R_ARM_ABS32_NOI:
7728                     case R_ARM_REL32:
7729                     case R_ARM_REL32_NOI:
7730                     case R_ARM_MOVW_ABS_NC:
7731                     case R_ARM_MOVT_ABS:
7732                     case R_ARM_MOVW_PREL_NC:
7733                     case R_ARM_MOVT_PREL:
7734                     case R_ARM_THM_MOVW_ABS_NC:
7735                     case R_ARM_THM_MOVT_ABS:
7736                     case R_ARM_THM_MOVW_PREL_NC:
7737                     case R_ARM_THM_MOVT_PREL:
7738                       break;
7739                     default:
7740                       h->needs_plt = 1;
7741                       break;
7742                   }
7743
7744                 /* If we create a PLT entry, this relocation will reference
7745                    it, even if it's an ABS32 relocation.  */
7746                 h->plt.refcount += 1;
7747
7748                 if (r_type == R_ARM_THM_CALL)
7749                   eh->plt_thumb_refcount += 1;
7750               }
7751
7752             /* If we are creating a shared library or relocatable executable,
7753                and this is a reloc against a global symbol, or a non PC
7754                relative reloc against a local symbol, then we need to copy
7755                the reloc into the shared library.  However, if we are linking
7756                with -Bsymbolic, we do not need to copy a reloc against a
7757                global symbol which is defined in an object we are
7758                including in the link (i.e., DEF_REGULAR is set).  At
7759                this point we have not seen all the input files, so it is
7760                possible that DEF_REGULAR is not set now but will be set
7761                later (it is never cleared).  We account for that
7762                possibility below by storing information in the
7763                relocs_copied field of the hash table entry.  */
7764             if ((info->shared || htab->root.is_relocatable_executable)
7765                 && (sec->flags & SEC_ALLOC) != 0
7766                 && ((r_type == R_ARM_ABS32 || r_type == R_ARM_ABS32_NOI)
7767                     || (h != NULL && ! h->needs_plt
7768                         && (! info->symbolic || ! h->def_regular))))
7769               {
7770                 struct elf32_arm_relocs_copied *p, **head;
7771
7772                 /* When creating a shared object, we must copy these
7773                    reloc types into the output file.  We create a reloc
7774                    section in dynobj and make room for this reloc.  */
7775                 if (sreloc == NULL)
7776                   {
7777                     const char * name;
7778
7779                     name = (bfd_elf_string_from_elf_section
7780                             (abfd,
7781                              elf_elfheader (abfd)->e_shstrndx,
7782                              elf_section_data (sec)->rel_hdr.sh_name));
7783                     if (name == NULL)
7784                       return FALSE;
7785
7786                     BFD_ASSERT (reloc_section_p (htab, name, sec));
7787
7788                     sreloc = bfd_get_section_by_name (dynobj, name);
7789                     if (sreloc == NULL)
7790                       {
7791                         flagword flags;
7792
7793                         flags = (SEC_HAS_CONTENTS | SEC_READONLY
7794                                  | SEC_IN_MEMORY | SEC_LINKER_CREATED);
7795                         if ((sec->flags & SEC_ALLOC) != 0
7796                             /* BPABI objects never have dynamic
7797                                relocations mapped.  */
7798                             && !htab->symbian_p)
7799                           flags |= SEC_ALLOC | SEC_LOAD;
7800                         sreloc = bfd_make_section_with_flags (dynobj,
7801                                                               name,
7802                                                               flags);
7803                         if (sreloc == NULL
7804                             || ! bfd_set_section_alignment (dynobj, sreloc, 2))
7805                           return FALSE;
7806                       }
7807
7808                     elf_section_data (sec)->sreloc = sreloc;
7809                   }
7810
7811                 /* If this is a global symbol, we count the number of
7812                    relocations we need for this symbol.  */
7813                 if (h != NULL)
7814                   {
7815                     head = &((struct elf32_arm_link_hash_entry *) h)->relocs_copied;
7816                   }
7817                 else
7818                   {
7819                     /* Track dynamic relocs needed for local syms too.
7820                        We really need local syms available to do this
7821                        easily.  Oh well.  */
7822
7823                     asection *s;
7824                     void *vpp;
7825
7826                     s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
7827                                                    sec, r_symndx);
7828                     if (s == NULL)
7829                       return FALSE;
7830
7831                     vpp = &elf_section_data (s)->local_dynrel;
7832                     head = (struct elf32_arm_relocs_copied **) vpp;
7833                   }
7834
7835                 p = *head;
7836                 if (p == NULL || p->section != sec)
7837                   {
7838                     bfd_size_type amt = sizeof *p;
7839
7840                     p = bfd_alloc (htab->root.dynobj, amt);
7841                     if (p == NULL)
7842                       return FALSE;
7843                     p->next = *head;
7844                     *head = p;
7845                     p->section = sec;
7846                     p->count = 0;
7847                     p->pc_count = 0;
7848                   }
7849
7850                 if (r_type == R_ARM_REL32 || r_type == R_ARM_REL32_NOI)
7851                   p->pc_count += 1;
7852                 p->count += 1;
7853               }
7854             break;
7855
7856         /* This relocation describes the C++ object vtable hierarchy.
7857            Reconstruct it for later use during GC.  */
7858         case R_ARM_GNU_VTINHERIT:
7859           if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
7860             return FALSE;
7861           break;
7862
7863         /* This relocation describes which C++ vtable entries are actually
7864            used.  Record for later use during GC.  */
7865         case R_ARM_GNU_VTENTRY:
7866           if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset))
7867             return FALSE;
7868           break;
7869         }
7870     }
7871
7872   return TRUE;
7873 }
7874
7875 /* Unwinding tables are not referenced directly.  This pass marks them as
7876    required if the corresponding code section is marked.  */
7877
7878 static bfd_boolean
7879 elf32_arm_gc_mark_extra_sections(struct bfd_link_info *info,
7880                                  elf_gc_mark_hook_fn gc_mark_hook)
7881 {
7882   bfd *sub;
7883   Elf_Internal_Shdr **elf_shdrp;
7884   bfd_boolean again;
7885
7886   /* Marking EH data may cause additional code sections to be marked,
7887      requiring multiple passes.  */
7888   again = TRUE;
7889   while (again)
7890     {
7891       again = FALSE;
7892       for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
7893         {
7894           asection *o;
7895
7896           if (bfd_get_flavour (sub) != bfd_target_elf_flavour)
7897             continue;
7898
7899           elf_shdrp = elf_elfsections (sub);
7900           for (o = sub->sections; o != NULL; o = o->next)
7901             {
7902               Elf_Internal_Shdr *hdr;
7903               hdr = &elf_section_data (o)->this_hdr;
7904               if (hdr->sh_type == SHT_ARM_EXIDX && hdr->sh_link
7905                   && !o->gc_mark
7906                   && elf_shdrp[hdr->sh_link]->bfd_section->gc_mark)
7907                 {
7908                   again = TRUE;
7909                   if (!_bfd_elf_gc_mark (info, o, gc_mark_hook))
7910                     return FALSE;
7911                 }
7912             }
7913         }
7914     }
7915
7916   return TRUE;
7917 }
7918
7919 /* Treat mapping symbols as special target symbols.  */
7920
7921 static bfd_boolean
7922 elf32_arm_is_target_special_symbol (bfd * abfd ATTRIBUTE_UNUSED, asymbol * sym)
7923 {
7924   return bfd_is_arm_special_symbol_name (sym->name,
7925                                          BFD_ARM_SPECIAL_SYM_TYPE_ANY);
7926 }
7927
7928 /* This is a copy of elf_find_function() from elf.c except that
7929    ARM mapping symbols are ignored when looking for function names
7930    and STT_ARM_TFUNC is considered to a function type.  */
7931
7932 static bfd_boolean
7933 arm_elf_find_function (bfd *         abfd ATTRIBUTE_UNUSED,
7934                        asection *    section,
7935                        asymbol **    symbols,
7936                        bfd_vma       offset,
7937                        const char ** filename_ptr,
7938                        const char ** functionname_ptr)
7939 {
7940   const char * filename = NULL;
7941   asymbol * func = NULL;
7942   bfd_vma low_func = 0;
7943   asymbol ** p;
7944
7945   for (p = symbols; *p != NULL; p++)
7946     {
7947       elf_symbol_type *q;
7948
7949       q = (elf_symbol_type *) *p;
7950
7951       switch (ELF_ST_TYPE (q->internal_elf_sym.st_info))
7952         {
7953         default:
7954           break;
7955         case STT_FILE:
7956           filename = bfd_asymbol_name (&q->symbol);
7957           break;
7958         case STT_FUNC:
7959         case STT_ARM_TFUNC:
7960         case STT_NOTYPE:
7961           /* Skip mapping symbols.  */
7962           if ((q->symbol.flags & BSF_LOCAL)
7963               && bfd_is_arm_special_symbol_name (q->symbol.name,
7964                     BFD_ARM_SPECIAL_SYM_TYPE_ANY))
7965             continue;
7966           /* Fall through.  */
7967           if (bfd_get_section (&q->symbol) == section
7968               && q->symbol.value >= low_func
7969               && q->symbol.value <= offset)
7970             {
7971               func = (asymbol *) q;
7972               low_func = q->symbol.value;
7973             }
7974           break;
7975         }
7976     }
7977
7978   if (func == NULL)
7979     return FALSE;
7980
7981   if (filename_ptr)
7982     *filename_ptr = filename;
7983   if (functionname_ptr)
7984     *functionname_ptr = bfd_asymbol_name (func);
7985
7986   return TRUE;
7987 }  
7988
7989
7990 /* Find the nearest line to a particular section and offset, for error
7991    reporting.   This code is a duplicate of the code in elf.c, except
7992    that it uses arm_elf_find_function.  */
7993
7994 static bfd_boolean
7995 elf32_arm_find_nearest_line (bfd *          abfd,
7996                              asection *     section,
7997                              asymbol **     symbols,
7998                              bfd_vma        offset,
7999                              const char **  filename_ptr,
8000                              const char **  functionname_ptr,
8001                              unsigned int * line_ptr)
8002 {
8003   bfd_boolean found = FALSE;
8004
8005   /* We skip _bfd_dwarf1_find_nearest_line since no known ARM toolchain uses it.  */
8006
8007   if (_bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset,
8008                                      filename_ptr, functionname_ptr,
8009                                      line_ptr, 0,
8010                                      & elf_tdata (abfd)->dwarf2_find_line_info))
8011     {
8012       if (!*functionname_ptr)
8013         arm_elf_find_function (abfd, section, symbols, offset,
8014                                *filename_ptr ? NULL : filename_ptr,
8015                                functionname_ptr);
8016
8017       return TRUE;
8018     }
8019
8020   if (! _bfd_stab_section_find_nearest_line (abfd, symbols, section, offset,
8021                                              & found, filename_ptr,
8022                                              functionname_ptr, line_ptr,
8023                                              & elf_tdata (abfd)->line_info))
8024     return FALSE;
8025
8026   if (found && (*functionname_ptr || *line_ptr))
8027     return TRUE;
8028
8029   if (symbols == NULL)
8030     return FALSE;
8031
8032   if (! arm_elf_find_function (abfd, section, symbols, offset,
8033                                filename_ptr, functionname_ptr))
8034     return FALSE;
8035
8036   *line_ptr = 0;
8037   return TRUE;
8038 }
8039
8040 static bfd_boolean
8041 elf32_arm_find_inliner_info (bfd *          abfd,
8042                              const char **  filename_ptr,
8043                              const char **  functionname_ptr,
8044                              unsigned int * line_ptr)
8045 {
8046   bfd_boolean found;
8047   found = _bfd_dwarf2_find_inliner_info (abfd, filename_ptr,
8048                                          functionname_ptr, line_ptr,
8049                                          & elf_tdata (abfd)->dwarf2_find_line_info);
8050   return found;
8051 }
8052
8053 /* Adjust a symbol defined by a dynamic object and referenced by a
8054    regular object.  The current definition is in some section of the
8055    dynamic object, but we're not including those sections.  We have to
8056    change the definition to something the rest of the link can
8057    understand.  */
8058
8059 static bfd_boolean
8060 elf32_arm_adjust_dynamic_symbol (struct bfd_link_info * info,
8061                                  struct elf_link_hash_entry * h)
8062 {
8063   bfd * dynobj;
8064   asection * s;
8065   struct elf32_arm_link_hash_entry * eh;
8066   struct elf32_arm_link_hash_table *globals;
8067
8068   globals = elf32_arm_hash_table (info);
8069   dynobj = elf_hash_table (info)->dynobj;
8070
8071   /* Make sure we know what is going on here.  */
8072   BFD_ASSERT (dynobj != NULL
8073               && (h->needs_plt
8074                   || h->u.weakdef != NULL
8075                   || (h->def_dynamic
8076                       && h->ref_regular
8077                       && !h->def_regular)));
8078
8079   eh = (struct elf32_arm_link_hash_entry *) h;
8080
8081   /* If this is a function, put it in the procedure linkage table.  We
8082      will fill in the contents of the procedure linkage table later,
8083      when we know the address of the .got section.  */
8084   if (h->type == STT_FUNC || h->type == STT_ARM_TFUNC
8085       || h->needs_plt)
8086     {
8087       if (h->plt.refcount <= 0
8088           || SYMBOL_CALLS_LOCAL (info, h)
8089           || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
8090               && h->root.type == bfd_link_hash_undefweak))
8091         {
8092           /* This case can occur if we saw a PLT32 reloc in an input
8093              file, but the symbol was never referred to by a dynamic
8094              object, or if all references were garbage collected.  In
8095              such a case, we don't actually need to build a procedure
8096              linkage table, and we can just do a PC24 reloc instead.  */
8097           h->plt.offset = (bfd_vma) -1;
8098           eh->plt_thumb_refcount = 0;
8099           h->needs_plt = 0;
8100         }
8101
8102       return TRUE;
8103     }
8104   else
8105     {
8106       /* It's possible that we incorrectly decided a .plt reloc was
8107          needed for an R_ARM_PC24 or similar reloc to a non-function sym
8108          in check_relocs.  We can't decide accurately between function
8109          and non-function syms in check-relocs; Objects loaded later in
8110          the link may change h->type.  So fix it now.  */
8111       h->plt.offset = (bfd_vma) -1;
8112       eh->plt_thumb_refcount = 0;
8113     }
8114
8115   /* If this is a weak symbol, and there is a real definition, the
8116      processor independent code will have arranged for us to see the
8117      real definition first, and we can just use the same value.  */
8118   if (h->u.weakdef != NULL)
8119     {
8120       BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
8121                   || h->u.weakdef->root.type == bfd_link_hash_defweak);
8122       h->root.u.def.section = h->u.weakdef->root.u.def.section;
8123       h->root.u.def.value = h->u.weakdef->root.u.def.value;
8124       return TRUE;
8125     }
8126
8127   /* If there are no non-GOT references, we do not need a copy
8128      relocation.  */
8129   if (!h->non_got_ref)
8130     return TRUE;
8131
8132   /* This is a reference to a symbol defined by a dynamic object which
8133      is not a function.  */
8134
8135   /* If we are creating a shared library, we must presume that the
8136      only references to the symbol are via the global offset table.
8137      For such cases we need not do anything here; the relocations will
8138      be handled correctly by relocate_section.  Relocatable executables
8139      can reference data in shared objects directly, so we don't need to
8140      do anything here.  */
8141   if (info->shared || globals->root.is_relocatable_executable)
8142     return TRUE;
8143
8144   if (h->size == 0)
8145     {
8146       (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
8147                              h->root.root.string);
8148       return TRUE;
8149     }
8150
8151   /* We must allocate the symbol in our .dynbss section, which will
8152      become part of the .bss section of the executable.  There will be
8153      an entry for this symbol in the .dynsym section.  The dynamic
8154      object will contain position independent code, so all references
8155      from the dynamic object to this symbol will go through the global
8156      offset table.  The dynamic linker will use the .dynsym entry to
8157      determine the address it must put in the global offset table, so
8158      both the dynamic object and the regular object will refer to the
8159      same memory location for the variable.  */
8160   s = bfd_get_section_by_name (dynobj, ".dynbss");
8161   BFD_ASSERT (s != NULL);
8162
8163   /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to
8164      copy the initial value out of the dynamic object and into the
8165      runtime process image.  We need to remember the offset into the
8166      .rel(a).bss section we are going to use.  */
8167   if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
8168     {
8169       asection *srel;
8170
8171       srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (globals, ".bss"));
8172       BFD_ASSERT (srel != NULL);
8173       srel->size += RELOC_SIZE (globals);
8174       h->needs_copy = 1;
8175     }
8176
8177   return _bfd_elf_adjust_dynamic_copy (h, s);
8178 }
8179
8180 /* Allocate space in .plt, .got and associated reloc sections for
8181    dynamic relocs.  */
8182
8183 static bfd_boolean
8184 allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
8185 {
8186   struct bfd_link_info *info;
8187   struct elf32_arm_link_hash_table *htab;
8188   struct elf32_arm_link_hash_entry *eh;
8189   struct elf32_arm_relocs_copied *p;
8190
8191   eh = (struct elf32_arm_link_hash_entry *) h;
8192
8193   if (h->root.type == bfd_link_hash_indirect)
8194     return TRUE;
8195
8196   if (h->root.type == bfd_link_hash_warning)
8197     /* When warning symbols are created, they **replace** the "real"
8198        entry in the hash table, thus we never get to see the real
8199        symbol in a hash traversal.  So look at it now.  */
8200     h = (struct elf_link_hash_entry *) h->root.u.i.link;
8201
8202   info = (struct bfd_link_info *) inf;
8203   htab = elf32_arm_hash_table (info);
8204
8205   if (htab->root.dynamic_sections_created
8206       && h->plt.refcount > 0)
8207     {
8208       /* Make sure this symbol is output as a dynamic symbol.
8209          Undefined weak syms won't yet be marked as dynamic.  */
8210       if (h->dynindx == -1
8211           && !h->forced_local)
8212         {
8213           if (! bfd_elf_link_record_dynamic_symbol (info, h))
8214             return FALSE;
8215         }
8216
8217       if (info->shared
8218           || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
8219         {
8220           asection *s = htab->splt;
8221
8222           /* If this is the first .plt entry, make room for the special
8223              first entry.  */
8224           if (s->size == 0)
8225             s->size += htab->plt_header_size;
8226
8227           h->plt.offset = s->size;
8228
8229           /* If we will insert a Thumb trampoline before this PLT, leave room
8230              for it.  */
8231           if (!htab->use_blx && eh->plt_thumb_refcount > 0)
8232             {
8233               h->plt.offset += PLT_THUMB_STUB_SIZE;
8234               s->size += PLT_THUMB_STUB_SIZE;
8235             }
8236
8237           /* If this symbol is not defined in a regular file, and we are
8238              not generating a shared library, then set the symbol to this
8239              location in the .plt.  This is required to make function
8240              pointers compare as equal between the normal executable and
8241              the shared library.  */
8242           if (! info->shared
8243               && !h->def_regular)
8244             {
8245               h->root.u.def.section = s;
8246               h->root.u.def.value = h->plt.offset;
8247
8248               /* Make sure the function is not marked as Thumb, in case
8249                  it is the target of an ABS32 relocation, which will
8250                  point to the PLT entry.  */
8251               if (ELF_ST_TYPE (h->type) == STT_ARM_TFUNC)
8252                 h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC);
8253             }
8254
8255           /* Make room for this entry.  */
8256           s->size += htab->plt_entry_size;
8257
8258           if (!htab->symbian_p)
8259             {
8260               /* We also need to make an entry in the .got.plt section, which
8261                  will be placed in the .got section by the linker script.  */
8262               eh->plt_got_offset = htab->sgotplt->size;
8263               htab->sgotplt->size += 4;
8264             }
8265
8266           /* We also need to make an entry in the .rel(a).plt section.  */
8267           htab->srelplt->size += RELOC_SIZE (htab);
8268
8269           /* VxWorks executables have a second set of relocations for
8270              each PLT entry.  They go in a separate relocation section,
8271              which is processed by the kernel loader.  */
8272           if (htab->vxworks_p && !info->shared)
8273             {
8274               /* There is a relocation for the initial PLT entry:
8275                  an R_ARM_32 relocation for _GLOBAL_OFFSET_TABLE_.  */
8276               if (h->plt.offset == htab->plt_header_size)
8277                 htab->srelplt2->size += RELOC_SIZE (htab);
8278
8279               /* There are two extra relocations for each subsequent
8280                  PLT entry: an R_ARM_32 relocation for the GOT entry,
8281                  and an R_ARM_32 relocation for the PLT entry.  */
8282               htab->srelplt2->size += RELOC_SIZE (htab) * 2;
8283             }
8284         }
8285       else
8286         {
8287           h->plt.offset = (bfd_vma) -1;
8288           h->needs_plt = 0;
8289         }
8290     }
8291   else
8292     {
8293       h->plt.offset = (bfd_vma) -1;
8294       h->needs_plt = 0;
8295     }
8296
8297   if (h->got.refcount > 0)
8298     {
8299       asection *s;
8300       bfd_boolean dyn;
8301       int tls_type = elf32_arm_hash_entry (h)->tls_type;
8302       int indx;
8303
8304       /* Make sure this symbol is output as a dynamic symbol.
8305          Undefined weak syms won't yet be marked as dynamic.  */
8306       if (h->dynindx == -1
8307           && !h->forced_local)
8308         {
8309           if (! bfd_elf_link_record_dynamic_symbol (info, h))
8310             return FALSE;
8311         }
8312
8313       if (!htab->symbian_p)
8314         {
8315           s = htab->sgot;
8316           h->got.offset = s->size;
8317
8318           if (tls_type == GOT_UNKNOWN)
8319             abort ();
8320
8321           if (tls_type == GOT_NORMAL)
8322             /* Non-TLS symbols need one GOT slot.  */
8323             s->size += 4;
8324           else
8325             {
8326               if (tls_type & GOT_TLS_GD)
8327                 /* R_ARM_TLS_GD32 needs 2 consecutive GOT slots.  */
8328                 s->size += 8;
8329               if (tls_type & GOT_TLS_IE)
8330                 /* R_ARM_TLS_IE32 needs one GOT slot.  */
8331                 s->size += 4;
8332             }
8333
8334           dyn = htab->root.dynamic_sections_created;
8335
8336           indx = 0;
8337           if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
8338               && (!info->shared
8339                   || !SYMBOL_REFERENCES_LOCAL (info, h)))
8340             indx = h->dynindx;
8341
8342           if (tls_type != GOT_NORMAL
8343               && (info->shared || indx != 0)
8344               && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
8345                   || h->root.type != bfd_link_hash_undefweak))
8346             {
8347               if (tls_type & GOT_TLS_IE)
8348                 htab->srelgot->size += RELOC_SIZE (htab);
8349
8350               if (tls_type & GOT_TLS_GD)
8351                 htab->srelgot->size += RELOC_SIZE (htab);
8352
8353               if ((tls_type & GOT_TLS_GD) && indx != 0)
8354                 htab->srelgot->size += RELOC_SIZE (htab);
8355             }
8356           else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
8357                     || h->root.type != bfd_link_hash_undefweak)
8358                    && (info->shared
8359                    || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
8360             htab->srelgot->size += RELOC_SIZE (htab);
8361         }
8362     }
8363   else
8364     h->got.offset = (bfd_vma) -1;
8365
8366   /* Allocate stubs for exported Thumb functions on v4t.  */
8367   if (!htab->use_blx && h->dynindx != -1
8368       && h->def_regular
8369       && ELF_ST_TYPE (h->type) == STT_ARM_TFUNC
8370       && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
8371     {
8372       struct elf_link_hash_entry * th;
8373       struct bfd_link_hash_entry * bh;
8374       struct elf_link_hash_entry * myh;
8375       char name[1024];
8376       asection *s;
8377       bh = NULL;
8378       /* Create a new symbol to regist the real location of the function.  */
8379       s = h->root.u.def.section;
8380       sprintf(name, "__real_%s", h->root.root.string);
8381       _bfd_generic_link_add_one_symbol (info, s->owner,
8382                                         name, BSF_GLOBAL, s,
8383                                         h->root.u.def.value,
8384                                         NULL, TRUE, FALSE, &bh);
8385
8386       myh = (struct elf_link_hash_entry *) bh;
8387       myh->type = ELF_ST_INFO (STB_LOCAL, STT_ARM_TFUNC);
8388       myh->forced_local = 1;
8389       eh->export_glue = myh;
8390       th = record_arm_to_thumb_glue (info, h);
8391       /* Point the symbol at the stub.  */
8392       h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC);
8393       h->root.u.def.section = th->root.u.def.section;
8394       h->root.u.def.value = th->root.u.def.value & ~1;
8395     }
8396
8397   if (eh->relocs_copied == NULL)
8398     return TRUE;
8399
8400   /* In the shared -Bsymbolic case, discard space allocated for
8401      dynamic pc-relative relocs against symbols which turn out to be
8402      defined in regular objects.  For the normal shared case, discard
8403      space for pc-relative relocs that have become local due to symbol
8404      visibility changes.  */
8405
8406   if (info->shared || htab->root.is_relocatable_executable)
8407     {
8408       /* The only relocs that use pc_count are R_ARM_REL32 and
8409          R_ARM_REL32_NOI, which will appear on something like
8410          ".long foo - .".  We want calls to protected symbols to resolve
8411          directly to the function rather than going via the plt.  If people
8412          want function pointer comparisons to work as expected then they
8413          should avoid writing assembly like ".long foo - .".  */
8414       if (SYMBOL_CALLS_LOCAL (info, h))
8415         {
8416           struct elf32_arm_relocs_copied **pp;
8417
8418           for (pp = &eh->relocs_copied; (p = *pp) != NULL; )
8419             {
8420               p->count -= p->pc_count;
8421               p->pc_count = 0;
8422               if (p->count == 0)
8423                 *pp = p->next;
8424               else
8425                 pp = &p->next;
8426             }
8427         }
8428
8429       /* Also discard relocs on undefined weak syms with non-default
8430          visibility.  */
8431       if (eh->relocs_copied != NULL
8432           && h->root.type == bfd_link_hash_undefweak)
8433         {
8434           if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
8435             eh->relocs_copied = NULL;
8436
8437           /* Make sure undefined weak symbols are output as a dynamic
8438              symbol in PIEs.  */
8439           else if (h->dynindx == -1
8440                    && !h->forced_local)
8441             {
8442               if (! bfd_elf_link_record_dynamic_symbol (info, h))
8443                 return FALSE;
8444             }
8445         }
8446
8447       else if (htab->root.is_relocatable_executable && h->dynindx == -1
8448                && h->root.type == bfd_link_hash_new)
8449         {
8450           /* Output absolute symbols so that we can create relocations
8451              against them.  For normal symbols we output a relocation
8452              against the section that contains them.  */
8453           if (! bfd_elf_link_record_dynamic_symbol (info, h))
8454             return FALSE;
8455         }
8456
8457     }
8458   else
8459     {
8460       /* For the non-shared case, discard space for relocs against
8461          symbols which turn out to need copy relocs or are not
8462          dynamic.  */
8463
8464       if (!h->non_got_ref
8465           && ((h->def_dynamic
8466                && !h->def_regular)
8467               || (htab->root.dynamic_sections_created
8468                   && (h->root.type == bfd_link_hash_undefweak
8469                       || h->root.type == bfd_link_hash_undefined))))
8470         {
8471           /* Make sure this symbol is output as a dynamic symbol.
8472              Undefined weak syms won't yet be marked as dynamic.  */
8473           if (h->dynindx == -1
8474               && !h->forced_local)
8475             {
8476               if (! bfd_elf_link_record_dynamic_symbol (info, h))
8477                 return FALSE;
8478             }
8479
8480           /* If that succeeded, we know we'll be keeping all the
8481              relocs.  */
8482           if (h->dynindx != -1)
8483             goto keep;
8484         }
8485
8486       eh->relocs_copied = NULL;
8487
8488     keep: ;
8489     }
8490
8491   /* Finally, allocate space.  */
8492   for (p = eh->relocs_copied; p != NULL; p = p->next)
8493     {
8494       asection *sreloc = elf_section_data (p->section)->sreloc;
8495       sreloc->size += p->count * RELOC_SIZE (htab);
8496     }
8497
8498   return TRUE;
8499 }
8500
8501 /* Find any dynamic relocs that apply to read-only sections.  */
8502
8503 static bfd_boolean
8504 elf32_arm_readonly_dynrelocs (struct elf_link_hash_entry *h, PTR inf)
8505 {
8506   struct elf32_arm_link_hash_entry *eh;
8507   struct elf32_arm_relocs_copied *p;
8508
8509   if (h->root.type == bfd_link_hash_warning)
8510     h = (struct elf_link_hash_entry *) h->root.u.i.link;
8511
8512   eh = (struct elf32_arm_link_hash_entry *) h;
8513   for (p = eh->relocs_copied; p != NULL; p = p->next)
8514     {
8515       asection *s = p->section;
8516
8517       if (s != NULL && (s->flags & SEC_READONLY) != 0)
8518         {
8519           struct bfd_link_info *info = (struct bfd_link_info *) inf;
8520
8521           info->flags |= DF_TEXTREL;
8522
8523           /* Not an error, just cut short the traversal.  */
8524           return FALSE;
8525         }
8526     }
8527   return TRUE;
8528 }
8529
8530 void
8531 bfd_elf32_arm_set_byteswap_code (struct bfd_link_info *info,
8532                                  int byteswap_code)
8533 {
8534   struct elf32_arm_link_hash_table *globals;
8535
8536   globals = elf32_arm_hash_table (info);
8537   globals->byteswap_code = byteswap_code;
8538 }
8539
8540 /* Set the sizes of the dynamic sections.  */
8541
8542 static bfd_boolean
8543 elf32_arm_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED,
8544                                  struct bfd_link_info * info)
8545 {
8546   bfd * dynobj;
8547   asection * s;
8548   bfd_boolean plt;
8549   bfd_boolean relocs;
8550   bfd *ibfd;
8551   struct elf32_arm_link_hash_table *htab;
8552
8553   htab = elf32_arm_hash_table (info);
8554   dynobj = elf_hash_table (info)->dynobj;
8555   BFD_ASSERT (dynobj != NULL);
8556   check_use_blx (htab);
8557
8558   if (elf_hash_table (info)->dynamic_sections_created)
8559     {
8560       /* Set the contents of the .interp section to the interpreter.  */
8561       if (info->executable)
8562         {
8563           s = bfd_get_section_by_name (dynobj, ".interp");
8564           BFD_ASSERT (s != NULL);
8565           s->size = sizeof ELF_DYNAMIC_INTERPRETER;
8566           s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
8567         }
8568     }
8569
8570   /* Set up .got offsets for local syms, and space for local dynamic
8571      relocs.  */
8572   for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
8573     {
8574       bfd_signed_vma *local_got;
8575       bfd_signed_vma *end_local_got;
8576       char *local_tls_type;
8577       bfd_size_type locsymcount;
8578       Elf_Internal_Shdr *symtab_hdr;
8579       asection *srel;
8580
8581       if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
8582         continue;
8583
8584       for (s = ibfd->sections; s != NULL; s = s->next)
8585         {
8586           struct elf32_arm_relocs_copied *p;
8587
8588           for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next)
8589             {
8590               if (!bfd_is_abs_section (p->section)
8591                   && bfd_is_abs_section (p->section->output_section))
8592                 {
8593                   /* Input section has been discarded, either because
8594                      it is a copy of a linkonce section or due to
8595                      linker script /DISCARD/, so we'll be discarding
8596                      the relocs too.  */
8597                 }
8598               else if (p->count != 0)
8599                 {
8600                   srel = elf_section_data (p->section)->sreloc;
8601                   srel->size += p->count * RELOC_SIZE (htab);
8602                   if ((p->section->output_section->flags & SEC_READONLY) != 0)
8603                     info->flags |= DF_TEXTREL;
8604                 }
8605             }
8606         }
8607
8608       local_got = elf_local_got_refcounts (ibfd);
8609       if (!local_got)
8610         continue;
8611
8612       symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
8613       locsymcount = symtab_hdr->sh_info;
8614       end_local_got = local_got + locsymcount;
8615       local_tls_type = elf32_arm_local_got_tls_type (ibfd);
8616       s = htab->sgot;
8617       srel = htab->srelgot;
8618       for (; local_got < end_local_got; ++local_got, ++local_tls_type)
8619         {
8620           if (*local_got > 0)
8621             {
8622               *local_got = s->size;
8623               if (*local_tls_type & GOT_TLS_GD)
8624                 /* TLS_GD relocs need an 8-byte structure in the GOT.  */
8625                 s->size += 8;
8626               if (*local_tls_type & GOT_TLS_IE)
8627                 s->size += 4;
8628               if (*local_tls_type == GOT_NORMAL)
8629                 s->size += 4;
8630
8631               if (info->shared || *local_tls_type == GOT_TLS_GD)
8632                 srel->size += RELOC_SIZE (htab);
8633             }
8634           else
8635             *local_got = (bfd_vma) -1;
8636         }
8637     }
8638
8639   if (htab->tls_ldm_got.refcount > 0)
8640     {
8641       /* Allocate two GOT entries and one dynamic relocation (if necessary)
8642          for R_ARM_TLS_LDM32 relocations.  */
8643       htab->tls_ldm_got.offset = htab->sgot->size;
8644       htab->sgot->size += 8;
8645       if (info->shared)
8646         htab->srelgot->size += RELOC_SIZE (htab);
8647     }
8648   else
8649     htab->tls_ldm_got.offset = -1;
8650
8651   /* Allocate global sym .plt and .got entries, and space for global
8652      sym dynamic relocs.  */
8653   elf_link_hash_traverse (& htab->root, allocate_dynrelocs, info);
8654
8655   /* Here we rummage through the found bfds to collect glue information.  */
8656   for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
8657     {
8658       /* Initialise mapping tables for code/data.  */
8659       bfd_elf32_arm_init_maps (ibfd);
8660       
8661       if (!bfd_elf32_arm_process_before_allocation (ibfd, info)
8662           || !bfd_elf32_arm_vfp11_erratum_scan (ibfd, info))
8663         /* xgettext:c-format */
8664         _bfd_error_handler (_("Errors encountered processing file %s"),
8665                             ibfd->filename);
8666     }
8667
8668   /* The check_relocs and adjust_dynamic_symbol entry points have
8669      determined the sizes of the various dynamic sections.  Allocate
8670      memory for them.  */
8671   plt = FALSE;
8672   relocs = FALSE;
8673   for (s = dynobj->sections; s != NULL; s = s->next)
8674     {
8675       const char * name;
8676
8677       if ((s->flags & SEC_LINKER_CREATED) == 0)
8678         continue;
8679
8680       /* It's OK to base decisions on the section name, because none
8681          of the dynobj section names depend upon the input files.  */
8682       name = bfd_get_section_name (dynobj, s);
8683
8684       if (strcmp (name, ".plt") == 0)
8685         {
8686           /* Remember whether there is a PLT.  */
8687           plt = s->size != 0;
8688         }
8689       else if (CONST_STRNEQ (name, ".rel"))
8690         {
8691           if (s->size != 0)
8692             {
8693               /* Remember whether there are any reloc sections other
8694                  than .rel(a).plt and .rela.plt.unloaded.  */
8695               if (s != htab->srelplt && s != htab->srelplt2)
8696                 relocs = TRUE;
8697
8698               /* We use the reloc_count field as a counter if we need
8699                  to copy relocs into the output file.  */
8700               s->reloc_count = 0;
8701             }
8702         }
8703       else if (! CONST_STRNEQ (name, ".got")
8704                && strcmp (name, ".dynbss") != 0)
8705         {
8706           /* It's not one of our sections, so don't allocate space.  */
8707           continue;
8708         }
8709
8710       if (s->size == 0)
8711         {
8712           /* If we don't need this section, strip it from the
8713              output file.  This is mostly to handle .rel(a).bss and
8714              .rel(a).plt.  We must create both sections in
8715              create_dynamic_sections, because they must be created
8716              before the linker maps input sections to output
8717              sections.  The linker does that before
8718              adjust_dynamic_symbol is called, and it is that
8719              function which decides whether anything needs to go
8720              into these sections.  */
8721           s->flags |= SEC_EXCLUDE;
8722           continue;
8723         }
8724
8725       if ((s->flags & SEC_HAS_CONTENTS) == 0)
8726         continue;
8727
8728       /* Allocate memory for the section contents.  */
8729       s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
8730       if (s->contents == NULL)
8731         return FALSE;
8732     }
8733
8734   if (elf_hash_table (info)->dynamic_sections_created)
8735     {
8736       /* Add some entries to the .dynamic section.  We fill in the
8737          values later, in elf32_arm_finish_dynamic_sections, but we
8738          must add the entries now so that we get the correct size for
8739          the .dynamic section.  The DT_DEBUG entry is filled in by the
8740          dynamic linker and used by the debugger.  */
8741 #define add_dynamic_entry(TAG, VAL) \
8742   _bfd_elf_add_dynamic_entry (info, TAG, VAL)
8743
8744      if (info->executable)
8745         {
8746           if (!add_dynamic_entry (DT_DEBUG, 0))
8747             return FALSE;
8748         }
8749
8750       if (plt)
8751         {
8752           if (   !add_dynamic_entry (DT_PLTGOT, 0)
8753               || !add_dynamic_entry (DT_PLTRELSZ, 0)
8754               || !add_dynamic_entry (DT_PLTREL,
8755                                      htab->use_rel ? DT_REL : DT_RELA)
8756               || !add_dynamic_entry (DT_JMPREL, 0))
8757             return FALSE;
8758         }
8759
8760       if (relocs)
8761         {
8762           if (htab->use_rel)
8763             {
8764               if (!add_dynamic_entry (DT_REL, 0)
8765                   || !add_dynamic_entry (DT_RELSZ, 0)
8766                   || !add_dynamic_entry (DT_RELENT, RELOC_SIZE (htab)))
8767                 return FALSE;
8768             }
8769           else
8770             {
8771               if (!add_dynamic_entry (DT_RELA, 0)
8772                   || !add_dynamic_entry (DT_RELASZ, 0)
8773                   || !add_dynamic_entry (DT_RELAENT, RELOC_SIZE (htab)))
8774                 return FALSE;
8775             }
8776         }
8777
8778       /* If any dynamic relocs apply to a read-only section,
8779          then we need a DT_TEXTREL entry.  */
8780       if ((info->flags & DF_TEXTREL) == 0)
8781         elf_link_hash_traverse (&htab->root, elf32_arm_readonly_dynrelocs,
8782                                 (PTR) info);
8783
8784       if ((info->flags & DF_TEXTREL) != 0)
8785         {
8786           if (!add_dynamic_entry (DT_TEXTREL, 0))
8787             return FALSE;
8788         }
8789     }
8790 #undef add_dynamic_entry
8791
8792   return TRUE;
8793 }
8794
8795 /* Finish up dynamic symbol handling.  We set the contents of various
8796    dynamic sections here.  */
8797
8798 static bfd_boolean
8799 elf32_arm_finish_dynamic_symbol (bfd * output_bfd, struct bfd_link_info * info,
8800                                  struct elf_link_hash_entry * h, Elf_Internal_Sym * sym)
8801 {
8802   bfd * dynobj;
8803   struct elf32_arm_link_hash_table *htab;
8804   struct elf32_arm_link_hash_entry *eh;
8805
8806   dynobj = elf_hash_table (info)->dynobj;
8807   htab = elf32_arm_hash_table (info);
8808   eh = (struct elf32_arm_link_hash_entry *) h;
8809
8810   if (h->plt.offset != (bfd_vma) -1)
8811     {
8812       asection * splt;
8813       asection * srel;
8814       bfd_byte *loc;
8815       bfd_vma plt_index;
8816       Elf_Internal_Rela rel;
8817
8818       /* This symbol has an entry in the procedure linkage table.  Set
8819          it up.  */
8820
8821       BFD_ASSERT (h->dynindx != -1);
8822
8823       splt = bfd_get_section_by_name (dynobj, ".plt");
8824       srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (htab, ".plt"));
8825       BFD_ASSERT (splt != NULL && srel != NULL);
8826
8827       /* Fill in the entry in the procedure linkage table.  */
8828       if (htab->symbian_p)
8829         {
8830           put_arm_insn (htab, output_bfd, 
8831                       elf32_arm_symbian_plt_entry[0],
8832                       splt->contents + h->plt.offset);
8833           bfd_put_32 (output_bfd, 
8834                       elf32_arm_symbian_plt_entry[1],
8835                       splt->contents + h->plt.offset + 4);
8836           
8837           /* Fill in the entry in the .rel.plt section.  */
8838           rel.r_offset = (splt->output_section->vma
8839                           + splt->output_offset
8840                           + h->plt.offset + 4);
8841           rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT);
8842
8843           /* Get the index in the procedure linkage table which
8844              corresponds to this symbol.  This is the index of this symbol
8845              in all the symbols for which we are making plt entries.  The
8846              first entry in the procedure linkage table is reserved.  */
8847           plt_index = ((h->plt.offset - htab->plt_header_size) 
8848                        / htab->plt_entry_size);
8849         }
8850       else
8851         {
8852           bfd_vma got_offset, got_address, plt_address;
8853           bfd_vma got_displacement;
8854           asection * sgot;
8855           bfd_byte * ptr;
8856           
8857           sgot = bfd_get_section_by_name (dynobj, ".got.plt");
8858           BFD_ASSERT (sgot != NULL);
8859
8860           /* Get the offset into the .got.plt table of the entry that
8861              corresponds to this function.  */
8862           got_offset = eh->plt_got_offset;
8863
8864           /* Get the index in the procedure linkage table which
8865              corresponds to this symbol.  This is the index of this symbol
8866              in all the symbols for which we are making plt entries.  The
8867              first three entries in .got.plt are reserved; after that
8868              symbols appear in the same order as in .plt.  */
8869           plt_index = (got_offset - 12) / 4;
8870
8871           /* Calculate the address of the GOT entry.  */
8872           got_address = (sgot->output_section->vma
8873                          + sgot->output_offset
8874                          + got_offset);
8875
8876           /* ...and the address of the PLT entry.  */
8877           plt_address = (splt->output_section->vma
8878                          + splt->output_offset
8879                          + h->plt.offset);
8880
8881           ptr = htab->splt->contents + h->plt.offset;
8882           if (htab->vxworks_p && info->shared)
8883             {
8884               unsigned int i;
8885               bfd_vma val;
8886
8887               for (i = 0; i != htab->plt_entry_size / 4; i++, ptr += 4)
8888                 {
8889                   val = elf32_arm_vxworks_shared_plt_entry[i];
8890                   if (i == 2)
8891                     val |= got_address - sgot->output_section->vma;
8892                   if (i == 5)
8893                     val |= plt_index * RELOC_SIZE (htab);
8894                   if (i == 2 || i == 5)
8895                     bfd_put_32 (output_bfd, val, ptr);
8896                   else
8897                     put_arm_insn (htab, output_bfd, val, ptr);
8898                 }
8899             }
8900           else if (htab->vxworks_p)
8901             {
8902               unsigned int i;
8903               bfd_vma val;
8904
8905               for (i = 0; i != htab->plt_entry_size / 4; i++, ptr += 4)
8906                 {
8907                   val = elf32_arm_vxworks_exec_plt_entry[i];
8908                   if (i == 2)
8909                     val |= got_address;
8910                   if (i == 4)
8911                     val |= 0xffffff & -((h->plt.offset + i * 4 + 8) >> 2);
8912                   if (i == 5)
8913                     val |= plt_index * RELOC_SIZE (htab);
8914                   if (i == 2 || i == 5)
8915                     bfd_put_32 (output_bfd, val, ptr);
8916                   else
8917                     put_arm_insn (htab, output_bfd, val, ptr);
8918                 }
8919
8920               loc = (htab->srelplt2->contents
8921                      + (plt_index * 2 + 1) * RELOC_SIZE (htab));
8922
8923               /* Create the .rela.plt.unloaded R_ARM_ABS32 relocation
8924                  referencing the GOT for this PLT entry.  */
8925               rel.r_offset = plt_address + 8;
8926               rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
8927               rel.r_addend = got_offset;
8928               SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
8929               loc += RELOC_SIZE (htab);
8930
8931               /* Create the R_ARM_ABS32 relocation referencing the
8932                  beginning of the PLT for this GOT entry.  */
8933               rel.r_offset = got_address;
8934               rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32);
8935               rel.r_addend = 0;
8936               SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
8937             }
8938           else
8939             {
8940               /* Calculate the displacement between the PLT slot and the
8941                  entry in the GOT.  The eight-byte offset accounts for the
8942                  value produced by adding to pc in the first instruction
8943                  of the PLT stub.  */
8944               got_displacement = got_address - (plt_address + 8);
8945
8946               BFD_ASSERT ((got_displacement & 0xf0000000) == 0);
8947
8948               if (!htab->use_blx && eh->plt_thumb_refcount > 0)
8949                 {
8950                   put_thumb_insn (htab, output_bfd,
8951                                   elf32_arm_plt_thumb_stub[0], ptr - 4);
8952                   put_thumb_insn (htab, output_bfd,
8953                                   elf32_arm_plt_thumb_stub[1], ptr - 2);
8954                 }
8955
8956               put_arm_insn (htab, output_bfd,
8957                             elf32_arm_plt_entry[0]
8958                             | ((got_displacement & 0x0ff00000) >> 20),
8959                             ptr + 0);
8960               put_arm_insn (htab, output_bfd,
8961                             elf32_arm_plt_entry[1]
8962                             | ((got_displacement & 0x000ff000) >> 12),
8963                             ptr+ 4);
8964               put_arm_insn (htab, output_bfd,
8965                             elf32_arm_plt_entry[2]
8966                             | (got_displacement & 0x00000fff),
8967                             ptr + 8);
8968 #ifdef FOUR_WORD_PLT
8969               bfd_put_32 (output_bfd, elf32_arm_plt_entry[3], ptr + 12);
8970 #endif
8971             }
8972
8973           /* Fill in the entry in the global offset table.  */
8974           bfd_put_32 (output_bfd,
8975                       (splt->output_section->vma
8976                        + splt->output_offset),
8977                       sgot->contents + got_offset);
8978           
8979           /* Fill in the entry in the .rel(a).plt section.  */
8980           rel.r_addend = 0;
8981           rel.r_offset = got_address;
8982           rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_JUMP_SLOT);
8983         }
8984
8985       loc = srel->contents + plt_index * RELOC_SIZE (htab);
8986       SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
8987
8988       if (!h->def_regular)
8989         {
8990           /* Mark the symbol as undefined, rather than as defined in
8991              the .plt section.  Leave the value alone.  */
8992           sym->st_shndx = SHN_UNDEF;
8993           /* If the symbol is weak, we do need to clear the value.
8994              Otherwise, the PLT entry would provide a definition for
8995              the symbol even if the symbol wasn't defined anywhere,
8996              and so the symbol would never be NULL.  */
8997           if (!h->ref_regular_nonweak)
8998             sym->st_value = 0;
8999         }
9000     }
9001
9002   if (h->got.offset != (bfd_vma) -1
9003       && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_GD) == 0
9004       && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_IE) == 0)
9005     {
9006       asection * sgot;
9007       asection * srel;
9008       Elf_Internal_Rela rel;
9009       bfd_byte *loc;
9010       bfd_vma offset;
9011
9012       /* This symbol has an entry in the global offset table.  Set it
9013          up.  */
9014       sgot = bfd_get_section_by_name (dynobj, ".got");
9015       srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (htab, ".got"));
9016       BFD_ASSERT (sgot != NULL && srel != NULL);
9017
9018       offset = (h->got.offset & ~(bfd_vma) 1);
9019       rel.r_addend = 0;
9020       rel.r_offset = (sgot->output_section->vma
9021                       + sgot->output_offset
9022                       + offset);
9023
9024       /* If this is a static link, or it is a -Bsymbolic link and the
9025          symbol is defined locally or was forced to be local because
9026          of a version file, we just want to emit a RELATIVE reloc.
9027          The entry in the global offset table will already have been
9028          initialized in the relocate_section function.  */
9029       if (info->shared
9030           && SYMBOL_REFERENCES_LOCAL (info, h))
9031         {
9032           BFD_ASSERT((h->got.offset & 1) != 0);
9033           rel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
9034           if (!htab->use_rel)
9035             {
9036               rel.r_addend = bfd_get_32 (output_bfd, sgot->contents + offset);
9037               bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + offset);
9038             }
9039         }
9040       else
9041         {
9042           BFD_ASSERT((h->got.offset & 1) == 0);
9043           bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + offset);
9044           rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT);
9045         }
9046
9047       loc = srel->contents + srel->reloc_count++ * RELOC_SIZE (htab);
9048       SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
9049     }
9050
9051   if (h->needs_copy)
9052     {
9053       asection * s;
9054       Elf_Internal_Rela rel;
9055       bfd_byte *loc;
9056
9057       /* This symbol needs a copy reloc.  Set it up.  */
9058       BFD_ASSERT (h->dynindx != -1
9059                   && (h->root.type == bfd_link_hash_defined
9060                       || h->root.type == bfd_link_hash_defweak));
9061
9062       s = bfd_get_section_by_name (h->root.u.def.section->owner,
9063                                    RELOC_SECTION (htab, ".bss"));
9064       BFD_ASSERT (s != NULL);
9065
9066       rel.r_addend = 0;
9067       rel.r_offset = (h->root.u.def.value
9068                       + h->root.u.def.section->output_section->vma
9069                       + h->root.u.def.section->output_offset);
9070       rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_COPY);
9071       loc = s->contents + s->reloc_count++ * RELOC_SIZE (htab);
9072       SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
9073     }
9074
9075   /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute.  On VxWorks,
9076      the _GLOBAL_OFFSET_TABLE_ symbol is not absolute: it is relative
9077      to the ".got" section.  */
9078   if (strcmp (h->root.root.string, "_DYNAMIC") == 0
9079       || (!htab->vxworks_p && h == htab->root.hgot))
9080     sym->st_shndx = SHN_ABS;
9081
9082   return TRUE;
9083 }
9084
9085 /* Finish up the dynamic sections.  */
9086
9087 static bfd_boolean
9088 elf32_arm_finish_dynamic_sections (bfd * output_bfd, struct bfd_link_info * info)
9089 {
9090   bfd * dynobj;
9091   asection * sgot;
9092   asection * sdyn;
9093
9094   dynobj = elf_hash_table (info)->dynobj;
9095
9096   sgot = bfd_get_section_by_name (dynobj, ".got.plt");
9097   BFD_ASSERT (elf32_arm_hash_table (info)->symbian_p || sgot != NULL);
9098   sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
9099
9100   if (elf_hash_table (info)->dynamic_sections_created)
9101     {
9102       asection *splt;
9103       Elf32_External_Dyn *dyncon, *dynconend;
9104       struct elf32_arm_link_hash_table *htab;
9105
9106       htab = elf32_arm_hash_table (info);
9107       splt = bfd_get_section_by_name (dynobj, ".plt");
9108       BFD_ASSERT (splt != NULL && sdyn != NULL);
9109
9110       dyncon = (Elf32_External_Dyn *) sdyn->contents;
9111       dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
9112
9113       for (; dyncon < dynconend; dyncon++)
9114         {
9115           Elf_Internal_Dyn dyn;
9116           const char * name;
9117           asection * s;
9118
9119           bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
9120
9121           switch (dyn.d_tag)
9122             {
9123               unsigned int type;
9124
9125             default:
9126               break;
9127
9128             case DT_HASH:
9129               name = ".hash";
9130               goto get_vma_if_bpabi;
9131             case DT_STRTAB:
9132               name = ".dynstr";
9133               goto get_vma_if_bpabi;
9134             case DT_SYMTAB:
9135               name = ".dynsym";
9136               goto get_vma_if_bpabi;
9137             case DT_VERSYM:
9138               name = ".gnu.version";
9139               goto get_vma_if_bpabi;
9140             case DT_VERDEF:
9141               name = ".gnu.version_d";
9142               goto get_vma_if_bpabi;
9143             case DT_VERNEED:
9144               name = ".gnu.version_r";
9145               goto get_vma_if_bpabi;
9146
9147             case DT_PLTGOT:
9148               name = ".got";
9149               goto get_vma;
9150             case DT_JMPREL:
9151               name = RELOC_SECTION (htab, ".plt");
9152             get_vma:
9153               s = bfd_get_section_by_name (output_bfd, name);
9154               BFD_ASSERT (s != NULL);
9155               if (!htab->symbian_p)
9156                 dyn.d_un.d_ptr = s->vma;
9157               else
9158                 /* In the BPABI, tags in the PT_DYNAMIC section point
9159                    at the file offset, not the memory address, for the
9160                    convenience of the post linker.  */
9161                 dyn.d_un.d_ptr = s->filepos;
9162               bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
9163               break;
9164
9165             get_vma_if_bpabi:
9166               if (htab->symbian_p)
9167                 goto get_vma;
9168               break;
9169
9170             case DT_PLTRELSZ:
9171               s = bfd_get_section_by_name (output_bfd,
9172                                            RELOC_SECTION (htab, ".plt"));
9173               BFD_ASSERT (s != NULL);
9174               dyn.d_un.d_val = s->size;
9175               bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
9176               break;
9177               
9178             case DT_RELSZ:
9179             case DT_RELASZ:
9180               if (!htab->symbian_p)
9181                 {
9182                   /* My reading of the SVR4 ABI indicates that the
9183                      procedure linkage table relocs (DT_JMPREL) should be
9184                      included in the overall relocs (DT_REL).  This is
9185                      what Solaris does.  However, UnixWare can not handle
9186                      that case.  Therefore, we override the DT_RELSZ entry
9187                      here to make it not include the JMPREL relocs.  Since
9188                      the linker script arranges for .rel(a).plt to follow all
9189                      other relocation sections, we don't have to worry
9190                      about changing the DT_REL entry.  */
9191                   s = bfd_get_section_by_name (output_bfd,
9192                                                RELOC_SECTION (htab, ".plt"));
9193                   if (s != NULL)
9194                     dyn.d_un.d_val -= s->size;
9195                   bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
9196                   break;
9197                 }
9198               /* Fall through */
9199
9200             case DT_REL:
9201             case DT_RELA:
9202               /* In the BPABI, the DT_REL tag must point at the file
9203                  offset, not the VMA, of the first relocation
9204                  section.  So, we use code similar to that in
9205                  elflink.c, but do not check for SHF_ALLOC on the
9206                  relcoation section, since relocations sections are
9207                  never allocated under the BPABI.  The comments above
9208                  about Unixware notwithstanding, we include all of the
9209                  relocations here.  */
9210               if (htab->symbian_p)
9211                 {
9212                   unsigned int i;
9213                   type = ((dyn.d_tag == DT_REL || dyn.d_tag == DT_RELSZ)
9214                           ? SHT_REL : SHT_RELA);
9215                   dyn.d_un.d_val = 0;
9216                   for (i = 1; i < elf_numsections (output_bfd); i++)
9217                     {
9218                       Elf_Internal_Shdr *hdr 
9219                         = elf_elfsections (output_bfd)[i];
9220                       if (hdr->sh_type == type)
9221                         {
9222                           if (dyn.d_tag == DT_RELSZ 
9223                               || dyn.d_tag == DT_RELASZ)
9224                             dyn.d_un.d_val += hdr->sh_size;
9225                           else if ((ufile_ptr) hdr->sh_offset
9226                                    <= dyn.d_un.d_val - 1)
9227                             dyn.d_un.d_val = hdr->sh_offset;
9228                         }
9229                     }
9230                   bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
9231                 }
9232               break;
9233
9234               /* Set the bottom bit of DT_INIT/FINI if the
9235                  corresponding function is Thumb.  */
9236             case DT_INIT:
9237               name = info->init_function;
9238               goto get_sym;
9239             case DT_FINI:
9240               name = info->fini_function;
9241             get_sym:
9242               /* If it wasn't set by elf_bfd_final_link
9243                  then there is nothing to adjust.  */
9244               if (dyn.d_un.d_val != 0)
9245                 {
9246                   struct elf_link_hash_entry * eh;
9247
9248                   eh = elf_link_hash_lookup (elf_hash_table (info), name,
9249                                              FALSE, FALSE, TRUE);
9250                   if (eh != (struct elf_link_hash_entry *) NULL
9251                       && ELF_ST_TYPE (eh->type) == STT_ARM_TFUNC)
9252                     {
9253                       dyn.d_un.d_val |= 1;
9254                       bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
9255                     }
9256                 }
9257               break;
9258             }
9259         }
9260
9261       /* Fill in the first entry in the procedure linkage table.  */
9262       if (splt->size > 0 && elf32_arm_hash_table (info)->plt_header_size)
9263         {
9264           const bfd_vma *plt0_entry;
9265           bfd_vma got_address, plt_address, got_displacement;
9266
9267           /* Calculate the addresses of the GOT and PLT.  */
9268           got_address = sgot->output_section->vma + sgot->output_offset;
9269           plt_address = splt->output_section->vma + splt->output_offset;
9270
9271           if (htab->vxworks_p)
9272             {
9273               /* The VxWorks GOT is relocated by the dynamic linker.
9274                  Therefore, we must emit relocations rather than simply
9275                  computing the values now.  */
9276               Elf_Internal_Rela rel;
9277
9278               plt0_entry = elf32_arm_vxworks_exec_plt0_entry;
9279               put_arm_insn (htab, output_bfd, plt0_entry[0],
9280                             splt->contents + 0);
9281               put_arm_insn (htab, output_bfd, plt0_entry[1],
9282                             splt->contents + 4);
9283               put_arm_insn (htab, output_bfd, plt0_entry[2],
9284                             splt->contents + 8);
9285               bfd_put_32 (output_bfd, got_address, splt->contents + 12);
9286
9287               /* Generate a relocation for _GLOBAL_OFFSET_TABLE_. */
9288               rel.r_offset = plt_address + 12;
9289               rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
9290               rel.r_addend = 0;
9291               SWAP_RELOC_OUT (htab) (output_bfd, &rel,
9292                                      htab->srelplt2->contents);
9293             }
9294           else
9295             {
9296               got_displacement = got_address - (plt_address + 16);
9297
9298               plt0_entry = elf32_arm_plt0_entry;
9299               put_arm_insn (htab, output_bfd, plt0_entry[0],
9300                             splt->contents + 0);
9301               put_arm_insn (htab, output_bfd, plt0_entry[1],
9302                             splt->contents + 4);
9303               put_arm_insn (htab, output_bfd, plt0_entry[2],
9304                             splt->contents + 8);
9305               put_arm_insn (htab, output_bfd, plt0_entry[3],
9306                             splt->contents + 12);
9307
9308 #ifdef FOUR_WORD_PLT
9309               /* The displacement value goes in the otherwise-unused
9310                  last word of the second entry.  */
9311               bfd_put_32 (output_bfd, got_displacement, splt->contents + 28);
9312 #else
9313               bfd_put_32 (output_bfd, got_displacement, splt->contents + 16);
9314 #endif
9315             }
9316         }
9317
9318       /* UnixWare sets the entsize of .plt to 4, although that doesn't
9319          really seem like the right value.  */
9320       if (splt->output_section->owner == output_bfd)
9321         elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
9322
9323       if (htab->vxworks_p && !info->shared && htab->splt->size > 0)
9324         {
9325           /* Correct the .rel(a).plt.unloaded relocations.  They will have
9326              incorrect symbol indexes.  */
9327           int num_plts;
9328           unsigned char *p;
9329
9330           num_plts = ((htab->splt->size - htab->plt_header_size)
9331                       / htab->plt_entry_size);
9332           p = htab->srelplt2->contents + RELOC_SIZE (htab);
9333
9334           for (; num_plts; num_plts--)
9335             {
9336               Elf_Internal_Rela rel;
9337
9338               SWAP_RELOC_IN (htab) (output_bfd, p, &rel);
9339               rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
9340               SWAP_RELOC_OUT (htab) (output_bfd, &rel, p);
9341               p += RELOC_SIZE (htab);
9342
9343               SWAP_RELOC_IN (htab) (output_bfd, p, &rel);
9344               rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32);
9345               SWAP_RELOC_OUT (htab) (output_bfd, &rel, p);
9346               p += RELOC_SIZE (htab);
9347             }
9348         }
9349     }
9350
9351   /* Fill in the first three entries in the global offset table.  */
9352   if (sgot)
9353     {
9354       if (sgot->size > 0)
9355         {
9356           if (sdyn == NULL)
9357             bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
9358           else
9359             bfd_put_32 (output_bfd,
9360                         sdyn->output_section->vma + sdyn->output_offset,
9361                         sgot->contents);
9362           bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
9363           bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
9364         }
9365
9366       elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
9367     }
9368
9369   return TRUE;
9370 }
9371
9372 static void
9373 elf32_arm_post_process_headers (bfd * abfd, struct bfd_link_info * link_info ATTRIBUTE_UNUSED)
9374 {
9375   Elf_Internal_Ehdr * i_ehdrp;  /* ELF file header, internal form.  */
9376   struct elf32_arm_link_hash_table *globals;
9377
9378   i_ehdrp = elf_elfheader (abfd);
9379
9380   if (EF_ARM_EABI_VERSION (i_ehdrp->e_flags) == EF_ARM_EABI_UNKNOWN)
9381     i_ehdrp->e_ident[EI_OSABI] = ARM_ELF_OS_ABI_VERSION;
9382   else
9383     i_ehdrp->e_ident[EI_OSABI] = 0;
9384   i_ehdrp->e_ident[EI_ABIVERSION] = ARM_ELF_ABI_VERSION;
9385
9386   if (link_info)
9387     {
9388       globals = elf32_arm_hash_table (link_info);
9389       if (globals->byteswap_code)
9390         i_ehdrp->e_flags |= EF_ARM_BE8;
9391     }
9392
9393   /*
9394    * For EABI 5, we have to tag dynamic binaries and execs as either
9395    * soft float or hard float.
9396    */
9397   if (EF_ARM_EABI_VERSION (i_ehdrp->e_flags) == EF_ARM_EABI_VER5 &&
9398       (i_ehdrp->e_type == ET_DYN || i_ehdrp->e_type == ET_EXEC))
9399     i_ehdrp->e_flags |=
9400       bfd_elf_get_obj_attr_int (abfd, OBJ_ATTR_PROC, Tag_ABI_VFP_args) ?
9401       EF_ARM_VFP_FLOAT : EF_ARM_SOFT_FLOAT;
9402 }
9403
9404 static enum elf_reloc_type_class
9405 elf32_arm_reloc_type_class (const Elf_Internal_Rela *rela)
9406 {
9407   switch ((int) ELF32_R_TYPE (rela->r_info))
9408     {
9409     case R_ARM_RELATIVE:
9410       return reloc_class_relative;
9411     case R_ARM_JUMP_SLOT:
9412       return reloc_class_plt;
9413     case R_ARM_COPY:
9414       return reloc_class_copy;
9415     default:
9416       return reloc_class_normal;
9417     }
9418 }
9419
9420 /* Set the right machine number for an Arm ELF file.  */
9421
9422 static bfd_boolean
9423 elf32_arm_section_flags (flagword *flags, const Elf_Internal_Shdr *hdr)
9424 {
9425   if (hdr->sh_type == SHT_NOTE)
9426     *flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_SAME_CONTENTS;
9427
9428   return TRUE;
9429 }
9430
9431 static void
9432 elf32_arm_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED)
9433 {
9434   bfd_arm_update_notes (abfd, ARM_NOTE_SECTION);
9435 }
9436
9437 /* Return TRUE if this is an unwinding table entry.  */
9438
9439 static bfd_boolean
9440 is_arm_elf_unwind_section_name (bfd * abfd ATTRIBUTE_UNUSED, const char * name)
9441 {
9442   return (CONST_STRNEQ (name, ELF_STRING_ARM_unwind)
9443           || CONST_STRNEQ (name, ELF_STRING_ARM_unwind_once));
9444 }
9445
9446
9447 /* Set the type and flags for an ARM section.  We do this by
9448    the section name, which is a hack, but ought to work.  */
9449
9450 static bfd_boolean
9451 elf32_arm_fake_sections (bfd * abfd, Elf_Internal_Shdr * hdr, asection * sec)
9452 {
9453   const char * name;
9454
9455   name = bfd_get_section_name (abfd, sec);
9456
9457   if (is_arm_elf_unwind_section_name (abfd, name))
9458     {
9459       hdr->sh_type = SHT_ARM_EXIDX;
9460       hdr->sh_flags |= SHF_LINK_ORDER;
9461     }
9462   return TRUE;
9463 }
9464
9465 /* Handle an ARM specific section when reading an object file.  This is
9466    called when bfd_section_from_shdr finds a section with an unknown
9467    type.  */
9468
9469 static bfd_boolean
9470 elf32_arm_section_from_shdr (bfd *abfd,
9471                              Elf_Internal_Shdr * hdr,
9472                              const char *name,
9473                              int shindex)
9474 {
9475   /* There ought to be a place to keep ELF backend specific flags, but
9476      at the moment there isn't one.  We just keep track of the
9477      sections by their name, instead.  Fortunately, the ABI gives
9478      names for all the ARM specific sections, so we will probably get
9479      away with this.  */
9480   switch (hdr->sh_type)
9481     {
9482     case SHT_ARM_EXIDX:
9483     case SHT_ARM_PREEMPTMAP:
9484     case SHT_ARM_ATTRIBUTES:
9485       break;
9486
9487     default:
9488       return FALSE;
9489     }
9490
9491   if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
9492     return FALSE;
9493
9494   return TRUE;
9495 }
9496
9497 /* A structure used to record a list of sections, independently
9498    of the next and prev fields in the asection structure.  */
9499 typedef struct section_list
9500 {
9501   asection * sec;
9502   struct section_list * next;
9503   struct section_list * prev;
9504 }
9505 section_list;
9506
9507 /* Unfortunately we need to keep a list of sections for which
9508    an _arm_elf_section_data structure has been allocated.  This
9509    is because it is possible for functions like elf32_arm_write_section
9510    to be called on a section which has had an elf_data_structure
9511    allocated for it (and so the used_by_bfd field is valid) but
9512    for which the ARM extended version of this structure - the
9513    _arm_elf_section_data structure - has not been allocated.  */
9514 static section_list * sections_with_arm_elf_section_data = NULL;
9515
9516 static void
9517 record_section_with_arm_elf_section_data (asection * sec)
9518 {
9519   struct section_list * entry;
9520
9521   entry = bfd_malloc (sizeof (* entry));
9522   if (entry == NULL)
9523     return;
9524   entry->sec = sec;
9525   entry->next = sections_with_arm_elf_section_data;
9526   entry->prev = NULL;
9527   if (entry->next != NULL)
9528     entry->next->prev = entry;
9529   sections_with_arm_elf_section_data = entry;
9530 }
9531
9532 static struct section_list *
9533 find_arm_elf_section_entry (asection * sec)
9534 {
9535   struct section_list * entry;
9536   static struct section_list * last_entry = NULL;
9537
9538   /* This is a short cut for the typical case where the sections are added
9539      to the sections_with_arm_elf_section_data list in forward order and
9540      then looked up here in backwards order.  This makes a real difference
9541      to the ld-srec/sec64k.exp linker test.  */
9542   entry = sections_with_arm_elf_section_data;
9543   if (last_entry != NULL)
9544     {
9545       if (last_entry->sec == sec)
9546         entry = last_entry;
9547       else if (last_entry->next != NULL
9548                && last_entry->next->sec == sec)
9549         entry = last_entry->next;
9550     }
9551
9552   for (; entry; entry = entry->next)
9553     if (entry->sec == sec)
9554       break;
9555
9556   if (entry)
9557     /* Record the entry prior to this one - it is the entry we are most
9558        likely to want to locate next time.  Also this way if we have been
9559        called from unrecord_section_with_arm_elf_section_data() we will not
9560        be caching a pointer that is about to be freed.  */
9561     last_entry = entry->prev;
9562
9563   return entry;
9564 }
9565
9566 static _arm_elf_section_data *
9567 get_arm_elf_section_data (asection * sec)
9568 {
9569   struct section_list * entry;
9570
9571   entry = find_arm_elf_section_entry (sec);
9572
9573   if (entry)
9574     return elf32_arm_section_data (entry->sec);
9575   else
9576     return NULL;
9577 }
9578
9579 static void
9580 unrecord_section_with_arm_elf_section_data (asection * sec)
9581 {
9582   struct section_list * entry;
9583
9584   entry = find_arm_elf_section_entry (sec);
9585
9586   if (entry)
9587     {
9588       if (entry->prev != NULL)
9589         entry->prev->next = entry->next;
9590       if (entry->next != NULL)
9591         entry->next->prev = entry->prev;
9592       if (entry == sections_with_arm_elf_section_data)
9593         sections_with_arm_elf_section_data = entry->next;
9594       free (entry);
9595     }
9596 }
9597
9598
9599 typedef struct
9600 {
9601   void *finfo;
9602   struct bfd_link_info *info;
9603   asection *sec;
9604   int sec_shndx;
9605   bfd_boolean (*func) (void *, const char *, Elf_Internal_Sym *,
9606                        asection *, struct elf_link_hash_entry *);
9607 } output_arch_syminfo;
9608
9609 enum map_symbol_type
9610 {
9611   ARM_MAP_ARM,
9612   ARM_MAP_THUMB,
9613   ARM_MAP_DATA
9614 };
9615
9616
9617 /* Output a single PLT mapping symbol.  */
9618
9619 static bfd_boolean
9620 elf32_arm_ouput_plt_map_sym (output_arch_syminfo *osi,
9621                              enum map_symbol_type type,
9622                              bfd_vma offset)
9623 {
9624   static const char *names[3] = {"$a", "$t", "$d"};
9625   struct elf32_arm_link_hash_table *htab;
9626   Elf_Internal_Sym sym;
9627
9628   htab = elf32_arm_hash_table (osi->info);
9629   sym.st_value = osi->sec->output_section->vma
9630                  + osi->sec->output_offset
9631                  + offset;
9632   sym.st_size = 0;
9633   sym.st_other = 0;
9634   sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
9635   sym.st_shndx = osi->sec_shndx;
9636   if (!osi->func (osi->finfo, names[type], &sym, osi->sec, NULL))
9637     return FALSE;
9638   return TRUE;
9639 }
9640
9641
9642 /* Output mapping symbols for PLT entries associated with H.  */
9643
9644 static bfd_boolean
9645 elf32_arm_output_plt_map (struct elf_link_hash_entry *h, void *inf)
9646 {
9647   output_arch_syminfo *osi = (output_arch_syminfo *) inf;
9648   struct elf32_arm_link_hash_table *htab;
9649   struct elf32_arm_link_hash_entry *eh;
9650   bfd_vma addr;
9651
9652   htab = elf32_arm_hash_table (osi->info);
9653
9654   if (h->root.type == bfd_link_hash_indirect)
9655     return TRUE;
9656
9657   if (h->root.type == bfd_link_hash_warning)
9658     /* When warning symbols are created, they **replace** the "real"
9659        entry in the hash table, thus we never get to see the real
9660        symbol in a hash traversal.  So look at it now.  */
9661     h = (struct elf_link_hash_entry *) h->root.u.i.link;
9662
9663   if (h->plt.offset == (bfd_vma) -1)
9664     return TRUE;
9665
9666   eh = (struct elf32_arm_link_hash_entry *) h;
9667   addr = h->plt.offset;
9668   if (htab->symbian_p)
9669     {
9670       if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr))
9671         return FALSE;
9672       if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 4))
9673         return FALSE;
9674     }
9675   else if (htab->vxworks_p)
9676     {
9677       if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr))
9678         return FALSE;
9679       if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 8))
9680         return FALSE;
9681       if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr + 12))
9682         return FALSE;
9683       if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 20))
9684         return FALSE;
9685     }
9686   else
9687     {
9688       bfd_boolean thumb_stub;
9689
9690       thumb_stub = eh->plt_thumb_refcount > 0 && !htab->use_blx;
9691       if (thumb_stub)
9692         {
9693           if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_THUMB, addr - 4))
9694             return FALSE;
9695         }
9696 #ifdef FOUR_WORD_PLT
9697       if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr))
9698         return FALSE;
9699       if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 12))
9700         return FALSE;
9701 #else
9702       /* A three-word PLT with no Thumb thunk contains only Arm code, 
9703          so only need to output a mapping symbol for the first PLT entry and
9704          entries with thumb thunks.  */
9705       if (thumb_stub || addr == 20)
9706         {
9707           if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr))
9708             return FALSE;
9709         }
9710 #endif
9711     }
9712
9713   return TRUE;
9714 }
9715
9716
9717 /* Output mapping symbols for linker generated sections.  */
9718
9719 static bfd_boolean
9720 elf32_arm_output_arch_local_syms (bfd *output_bfd,
9721     struct bfd_link_info *info,
9722     void *finfo, bfd_boolean (*func) (void *, const char *,
9723                                     Elf_Internal_Sym *,
9724                                     asection *,
9725                                     struct elf_link_hash_entry *))
9726 {
9727   output_arch_syminfo osi;
9728   struct elf32_arm_link_hash_table *htab;
9729   bfd_vma offset;
9730   bfd_size_type size;
9731
9732   htab = elf32_arm_hash_table (info);
9733   check_use_blx(htab);
9734
9735   osi.finfo = finfo;
9736   osi.info = info;
9737   osi.func = func;
9738   
9739   /* ARM->Thumb glue.  */
9740   if (htab->arm_glue_size > 0)
9741     {
9742       osi.sec = bfd_get_section_by_name (htab->bfd_of_glue_owner,
9743                                          ARM2THUMB_GLUE_SECTION_NAME);
9744
9745       osi.sec_shndx = _bfd_elf_section_from_bfd_section
9746           (output_bfd, osi.sec->output_section);
9747       if (info->shared || htab->root.is_relocatable_executable
9748           || htab->pic_veneer)
9749         size = ARM2THUMB_PIC_GLUE_SIZE;
9750       else if (htab->use_blx)
9751         size = ARM2THUMB_V5_STATIC_GLUE_SIZE;
9752       else
9753         size = ARM2THUMB_STATIC_GLUE_SIZE;
9754
9755       for (offset = 0; offset < htab->arm_glue_size; offset += size)
9756         {
9757           elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_ARM, offset);
9758           elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_DATA, offset + size - 4);
9759         }
9760     }
9761
9762   /* Thumb->ARM glue.  */
9763   if (htab->thumb_glue_size > 0)
9764     {
9765       osi.sec = bfd_get_section_by_name (htab->bfd_of_glue_owner,
9766                                          THUMB2ARM_GLUE_SECTION_NAME);
9767
9768       osi.sec_shndx = _bfd_elf_section_from_bfd_section
9769           (output_bfd, osi.sec->output_section);
9770       size = THUMB2ARM_GLUE_SIZE;
9771
9772       for (offset = 0; offset < htab->thumb_glue_size; offset += size)
9773         {
9774           elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_THUMB, offset);
9775           elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_ARM, offset + 4);
9776         }
9777     }
9778
9779   /* Finally, output mapping symbols for the PLT.  */
9780   if (!htab->splt || htab->splt->size == 0)
9781     return TRUE;
9782
9783   osi.sec_shndx = _bfd_elf_section_from_bfd_section (output_bfd,
9784       htab->splt->output_section);
9785   osi.sec = htab->splt;
9786   /* Output mapping symbols for the plt header.  SymbianOS does not have a
9787      plt header.  */
9788   if (htab->vxworks_p)
9789     {
9790       /* VxWorks shared libraries have no PLT header.  */
9791       if (!info->shared)
9792         {
9793           if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_ARM, 0))
9794             return FALSE;
9795           if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_DATA, 12))
9796             return FALSE;
9797         }
9798     }
9799   else if (!htab->symbian_p)
9800     {
9801       if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_ARM, 0))
9802         return FALSE;
9803 #ifndef FOUR_WORD_PLT
9804       if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_DATA, 16))
9805         return FALSE;
9806 #endif
9807     }
9808
9809   elf_link_hash_traverse (&htab->root, elf32_arm_output_plt_map, (void *) &osi);
9810   return TRUE;
9811 }
9812
9813 /* Allocate target specific section data.  */
9814
9815 static bfd_boolean
9816 elf32_arm_new_section_hook (bfd *abfd, asection *sec)
9817 {
9818   if (!sec->used_by_bfd)
9819     {
9820       _arm_elf_section_data *sdata;
9821       bfd_size_type amt = sizeof (*sdata);
9822
9823       sdata = bfd_zalloc (abfd, amt);
9824       if (sdata == NULL)
9825         return FALSE;
9826       sec->used_by_bfd = sdata;
9827     }
9828
9829   record_section_with_arm_elf_section_data (sec);
9830
9831   return _bfd_elf_new_section_hook (abfd, sec);
9832 }
9833
9834
9835 /* Used to order a list of mapping symbols by address.  */
9836
9837 static int
9838 elf32_arm_compare_mapping (const void * a, const void * b)
9839 {
9840   return ((const elf32_arm_section_map *) a)->vma
9841          > ((const elf32_arm_section_map *) b)->vma;
9842 }
9843
9844
9845 /* Do code byteswapping.  Return FALSE afterwards so that the section is
9846    written out as normal.  */
9847
9848 static bfd_boolean
9849 elf32_arm_write_section (bfd *output_bfd,
9850                          struct bfd_link_info *link_info, asection *sec,
9851                          bfd_byte *contents)
9852 {
9853   int mapcount, errcount;
9854   _arm_elf_section_data *arm_data;
9855   struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
9856   elf32_arm_section_map *map;
9857   elf32_vfp11_erratum_list *errnode;
9858   bfd_vma ptr;
9859   bfd_vma end;
9860   bfd_vma offset = sec->output_section->vma + sec->output_offset;
9861   bfd_byte tmp;
9862   int i;
9863
9864   /* If this section has not been allocated an _arm_elf_section_data
9865      structure then we cannot record anything.  */
9866   arm_data = get_arm_elf_section_data (sec);
9867   if (arm_data == NULL)
9868     return FALSE;
9869
9870   mapcount = arm_data->mapcount;
9871   map = arm_data->map;
9872   errcount = arm_data->erratumcount;
9873
9874   if (errcount != 0)
9875     {
9876       unsigned int endianflip = bfd_big_endian (output_bfd) ? 3 : 0;
9877
9878       for (errnode = arm_data->erratumlist; errnode != 0;
9879            errnode = errnode->next)
9880         {
9881           bfd_vma index = errnode->vma - offset;
9882
9883           switch (errnode->type)
9884             {
9885             case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER:
9886               {
9887                 bfd_vma branch_to_veneer;
9888                 /* Original condition code of instruction, plus bit mask for
9889                    ARM B instruction.  */
9890                 unsigned int insn = (errnode->u.b.vfp_insn & 0xf0000000)
9891                                   | 0x0a000000;
9892
9893                 /* The instruction is before the label.  */
9894                 index -= 4;
9895
9896                 /* Above offset included in -4 below.  */
9897                 branch_to_veneer = errnode->u.b.veneer->vma
9898                                    - errnode->vma - 4;
9899
9900                 if ((signed) branch_to_veneer < -(1 << 25)
9901                     || (signed) branch_to_veneer >= (1 << 25))
9902                   (*_bfd_error_handler) (_("%B: error: VFP11 veneer out of "
9903                                            "range"), output_bfd);
9904
9905                 insn |= (branch_to_veneer >> 2) & 0xffffff;
9906                 contents[endianflip ^ index] = insn & 0xff;
9907                 contents[endianflip ^ (index + 1)] = (insn >> 8) & 0xff;
9908                 contents[endianflip ^ (index + 2)] = (insn >> 16) & 0xff;
9909                 contents[endianflip ^ (index + 3)] = (insn >> 24) & 0xff;
9910               }
9911               break;
9912
9913             case VFP11_ERRATUM_ARM_VENEER:
9914               {
9915                 bfd_vma branch_from_veneer;
9916                 unsigned int insn;
9917
9918                 /* Take size of veneer into account.  */
9919                 branch_from_veneer = errnode->u.v.branch->vma
9920                                      - errnode->vma - 12;
9921
9922                 if ((signed) branch_from_veneer < -(1 << 25)
9923                     || (signed) branch_from_veneer >= (1 << 25))
9924                   (*_bfd_error_handler) (_("%B: error: VFP11 veneer out of "
9925                                            "range"), output_bfd);
9926
9927                 /* Original instruction.  */
9928                 insn = errnode->u.v.branch->u.b.vfp_insn;
9929                 contents[endianflip ^ index] = insn & 0xff;
9930                 contents[endianflip ^ (index + 1)] = (insn >> 8) & 0xff;
9931                 contents[endianflip ^ (index + 2)] = (insn >> 16) & 0xff;
9932                 contents[endianflip ^ (index + 3)] = (insn >> 24) & 0xff;
9933
9934                 /* Branch back to insn after original insn.  */
9935                 insn = 0xea000000 | ((branch_from_veneer >> 2) & 0xffffff);
9936                 contents[endianflip ^ (index + 4)] = insn & 0xff;
9937                 contents[endianflip ^ (index + 5)] = (insn >> 8) & 0xff;
9938                 contents[endianflip ^ (index + 6)] = (insn >> 16) & 0xff;
9939                 contents[endianflip ^ (index + 7)] = (insn >> 24) & 0xff;
9940               }
9941               break;
9942
9943             default:
9944               abort ();
9945             }
9946         }
9947     }
9948
9949   if (mapcount == 0)
9950     return FALSE;
9951
9952   if (globals->byteswap_code)
9953     {
9954       qsort (map, mapcount, sizeof (* map), elf32_arm_compare_mapping);
9955
9956       ptr = map[0].vma;
9957       for (i = 0; i < mapcount; i++)
9958         {
9959           if (i == mapcount - 1)
9960             end = sec->size;
9961           else
9962             end = map[i + 1].vma;
9963
9964           switch (map[i].type)
9965             {
9966             case 'a':
9967               /* Byte swap code words.  */
9968               while (ptr + 3 < end)
9969                 {
9970                   tmp = contents[ptr];
9971                   contents[ptr] = contents[ptr + 3];
9972                   contents[ptr + 3] = tmp;
9973                   tmp = contents[ptr + 1];
9974                   contents[ptr + 1] = contents[ptr + 2];
9975                   contents[ptr + 2] = tmp;
9976                   ptr += 4;
9977                 }
9978               break;
9979
9980             case 't':
9981               /* Byte swap code halfwords.  */
9982               while (ptr + 1 < end)
9983                 {
9984                   tmp = contents[ptr];
9985                   contents[ptr] = contents[ptr + 1];
9986                   contents[ptr + 1] = tmp;
9987                   ptr += 2;
9988                 }
9989               break;
9990
9991             case 'd':
9992               /* Leave data alone.  */
9993               break;
9994             }
9995           ptr = end;
9996         }
9997     }
9998
9999   free (map);
10000   arm_data->mapcount = 0;
10001   arm_data->mapsize = 0;
10002   arm_data->map = NULL;
10003   unrecord_section_with_arm_elf_section_data (sec);
10004
10005   return FALSE;
10006 }
10007
10008 static void
10009 unrecord_section_via_map_over_sections (bfd * abfd ATTRIBUTE_UNUSED,
10010                                         asection * sec,
10011                                         void * ignore ATTRIBUTE_UNUSED)
10012 {
10013   unrecord_section_with_arm_elf_section_data (sec);
10014 }
10015
10016 static bfd_boolean
10017 elf32_arm_close_and_cleanup (bfd * abfd)
10018 {
10019   if (abfd->sections)
10020     bfd_map_over_sections (abfd,
10021                            unrecord_section_via_map_over_sections,
10022                            NULL);
10023
10024   return _bfd_elf_close_and_cleanup (abfd);
10025 }
10026
10027 static bfd_boolean
10028 elf32_arm_bfd_free_cached_info (bfd * abfd)
10029 {
10030   if (abfd->sections)
10031     bfd_map_over_sections (abfd,
10032                            unrecord_section_via_map_over_sections,
10033                            NULL);
10034
10035   return _bfd_free_cached_info (abfd);
10036 }
10037
10038 /* Display STT_ARM_TFUNC symbols as functions.  */
10039
10040 static void
10041 elf32_arm_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
10042                              asymbol *asym)
10043 {
10044   elf_symbol_type *elfsym = (elf_symbol_type *) asym;
10045
10046   if (ELF_ST_TYPE (elfsym->internal_elf_sym.st_info) == STT_ARM_TFUNC)
10047     elfsym->symbol.flags |= BSF_FUNCTION;
10048 }
10049
10050
10051 /* Mangle thumb function symbols as we read them in.  */
10052
10053 static bfd_boolean
10054 elf32_arm_swap_symbol_in (bfd * abfd,
10055                           const void *psrc,
10056                           const void *pshn,
10057                           Elf_Internal_Sym *dst)
10058 {
10059   if (!bfd_elf32_swap_symbol_in (abfd, psrc, pshn, dst))
10060     return FALSE;
10061
10062   /* New EABI objects mark thumb function symbols by setting the low bit of
10063      the address.  Turn these into STT_ARM_TFUNC.  */
10064   if (ELF_ST_TYPE (dst->st_info) == STT_FUNC
10065       && (dst->st_value & 1))
10066     {
10067       dst->st_info = ELF_ST_INFO (ELF_ST_BIND (dst->st_info), STT_ARM_TFUNC);
10068       dst->st_value &= ~(bfd_vma) 1;
10069     }
10070   return TRUE;
10071 }
10072
10073
10074 /* Mangle thumb function symbols as we write them out.  */
10075
10076 static void
10077 elf32_arm_swap_symbol_out (bfd *abfd,
10078                            const Elf_Internal_Sym *src,
10079                            void *cdst,
10080                            void *shndx)
10081 {
10082   Elf_Internal_Sym newsym;
10083
10084   /* We convert STT_ARM_TFUNC symbols into STT_FUNC with the low bit
10085      of the address set, as per the new EABI.  We do this unconditionally
10086      because objcopy does not set the elf header flags until after
10087      it writes out the symbol table.  */
10088   if (ELF_ST_TYPE (src->st_info) == STT_ARM_TFUNC)
10089     {
10090       newsym = *src;
10091       newsym.st_info = ELF_ST_INFO (ELF_ST_BIND (src->st_info), STT_FUNC);
10092       if (newsym.st_shndx != SHN_UNDEF)
10093         {
10094           /* Do this only for defined symbols. At link type, the static
10095              linker will simulate the work of dynamic linker of resolving
10096              symbols and will carry over the thumbness of found symbols to
10097              the output symbol table. It's not clear how it happens, but
10098              the thumbness of undefined symbols can well be different at
10099              runtime, and writing '1' for them will be confusing for users
10100              and possibly for dynamic linker itself.
10101           */
10102           newsym.st_value |= 1;
10103         }
10104       
10105       src = &newsym;
10106     }
10107   bfd_elf32_swap_symbol_out (abfd, src, cdst, shndx);
10108 }
10109
10110 /* Add the PT_ARM_EXIDX program header.  */
10111
10112 static bfd_boolean
10113 elf32_arm_modify_segment_map (bfd *abfd, 
10114                               struct bfd_link_info *info ATTRIBUTE_UNUSED)
10115 {
10116   struct elf_segment_map *m;
10117   asection *sec;
10118
10119   sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
10120   if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
10121     {
10122       /* If there is already a PT_ARM_EXIDX header, then we do not
10123          want to add another one.  This situation arises when running
10124          "strip"; the input binary already has the header.  */
10125       m = elf_tdata (abfd)->segment_map;
10126       while (m && m->p_type != PT_ARM_EXIDX)
10127         m = m->next;
10128       if (!m)
10129         {
10130           m = bfd_zalloc (abfd, sizeof (struct elf_segment_map));
10131           if (m == NULL)
10132             return FALSE;
10133           m->p_type = PT_ARM_EXIDX;
10134           m->count = 1;
10135           m->sections[0] = sec;
10136
10137           m->next = elf_tdata (abfd)->segment_map;
10138           elf_tdata (abfd)->segment_map = m;
10139         }
10140     }
10141
10142   return TRUE;
10143 }
10144
10145 /* We may add a PT_ARM_EXIDX program header.  */
10146
10147 static int
10148 elf32_arm_additional_program_headers (bfd *abfd,
10149                                       struct bfd_link_info *info ATTRIBUTE_UNUSED)
10150 {
10151   asection *sec;
10152
10153   sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
10154   if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
10155     return 1;
10156   else
10157     return 0;
10158 }
10159
10160 /* We have two function types: STT_FUNC and STT_ARM_TFUNC.  */
10161 static bfd_boolean
10162 elf32_arm_is_function_type (unsigned int type)
10163 {
10164   return (type == STT_FUNC) || (type == STT_ARM_TFUNC);
10165 }
10166
10167 /* We use this to override swap_symbol_in and swap_symbol_out.  */
10168 const struct elf_size_info elf32_arm_size_info = {
10169   sizeof (Elf32_External_Ehdr),
10170   sizeof (Elf32_External_Phdr),
10171   sizeof (Elf32_External_Shdr),
10172   sizeof (Elf32_External_Rel),
10173   sizeof (Elf32_External_Rela),
10174   sizeof (Elf32_External_Sym),
10175   sizeof (Elf32_External_Dyn),
10176   sizeof (Elf_External_Note),
10177   4,
10178   1,
10179   32, 2,
10180   ELFCLASS32, EV_CURRENT,
10181   bfd_elf32_write_out_phdrs,
10182   bfd_elf32_write_shdrs_and_ehdr,
10183   bfd_elf32_write_relocs,
10184   elf32_arm_swap_symbol_in,
10185   elf32_arm_swap_symbol_out,
10186   bfd_elf32_slurp_reloc_table,
10187   bfd_elf32_slurp_symbol_table,
10188   bfd_elf32_swap_dyn_in,
10189   bfd_elf32_swap_dyn_out,
10190   bfd_elf32_swap_reloc_in,
10191   bfd_elf32_swap_reloc_out,
10192   bfd_elf32_swap_reloca_in,
10193   bfd_elf32_swap_reloca_out
10194 };
10195
10196 #define ELF_ARCH                        bfd_arch_arm
10197 #define ELF_MACHINE_CODE                EM_ARM
10198 #ifdef __QNXTARGET__
10199 #define ELF_MAXPAGESIZE                 0x1000
10200 #else
10201 #define ELF_MAXPAGESIZE                 0x8000
10202 #endif
10203 #define ELF_MINPAGESIZE                 0x1000
10204 #define ELF_COMMONPAGESIZE              0x1000
10205
10206 #define bfd_elf32_mkobject                      elf32_arm_mkobject
10207
10208 #define bfd_elf32_bfd_copy_private_bfd_data     elf32_arm_copy_private_bfd_data
10209 #define bfd_elf32_bfd_merge_private_bfd_data    elf32_arm_merge_private_bfd_data
10210 #define bfd_elf32_bfd_set_private_flags         elf32_arm_set_private_flags
10211 #define bfd_elf32_bfd_print_private_bfd_data    elf32_arm_print_private_bfd_data
10212 #define bfd_elf32_bfd_link_hash_table_create    elf32_arm_link_hash_table_create
10213 #define bfd_elf32_bfd_reloc_type_lookup         elf32_arm_reloc_type_lookup
10214 #define bfd_elf32_bfd_reloc_name_lookup elf32_arm_reloc_name_lookup
10215 #define bfd_elf32_find_nearest_line             elf32_arm_find_nearest_line
10216 #define bfd_elf32_find_inliner_info             elf32_arm_find_inliner_info
10217 #define bfd_elf32_new_section_hook              elf32_arm_new_section_hook
10218 #define bfd_elf32_bfd_is_target_special_symbol  elf32_arm_is_target_special_symbol
10219 #define bfd_elf32_close_and_cleanup             elf32_arm_close_and_cleanup
10220 #define bfd_elf32_bfd_free_cached_info          elf32_arm_bfd_free_cached_info
10221
10222 #define elf_backend_get_symbol_type             elf32_arm_get_symbol_type
10223 #define elf_backend_gc_mark_hook                elf32_arm_gc_mark_hook
10224 #define elf_backend_gc_mark_extra_sections      elf32_arm_gc_mark_extra_sections
10225 #define elf_backend_gc_sweep_hook               elf32_arm_gc_sweep_hook
10226 #define elf_backend_check_relocs                elf32_arm_check_relocs
10227 #define elf_backend_relocate_section            elf32_arm_relocate_section
10228 #define elf_backend_write_section               elf32_arm_write_section
10229 #define elf_backend_adjust_dynamic_symbol       elf32_arm_adjust_dynamic_symbol
10230 #define elf_backend_create_dynamic_sections     elf32_arm_create_dynamic_sections
10231 #define elf_backend_finish_dynamic_symbol       elf32_arm_finish_dynamic_symbol
10232 #define elf_backend_finish_dynamic_sections     elf32_arm_finish_dynamic_sections
10233 #define elf_backend_size_dynamic_sections       elf32_arm_size_dynamic_sections
10234 #define elf_backend_init_index_section          _bfd_elf_init_2_index_sections
10235 #define elf_backend_post_process_headers        elf32_arm_post_process_headers
10236 #define elf_backend_reloc_type_class            elf32_arm_reloc_type_class
10237 #define elf_backend_object_p                    elf32_arm_object_p
10238 #define elf_backend_section_flags               elf32_arm_section_flags
10239 #define elf_backend_fake_sections               elf32_arm_fake_sections
10240 #define elf_backend_section_from_shdr           elf32_arm_section_from_shdr
10241 #define elf_backend_final_write_processing      elf32_arm_final_write_processing
10242 #define elf_backend_copy_indirect_symbol        elf32_arm_copy_indirect_symbol
10243 #define elf_backend_symbol_processing           elf32_arm_symbol_processing
10244 #define elf_backend_size_info                   elf32_arm_size_info
10245 #define elf_backend_modify_segment_map          elf32_arm_modify_segment_map
10246 #define elf_backend_additional_program_headers \
10247   elf32_arm_additional_program_headers
10248 #define elf_backend_output_arch_local_syms \
10249   elf32_arm_output_arch_local_syms
10250 #define elf_backend_begin_write_processing \
10251     elf32_arm_begin_write_processing
10252 #define elf_backend_is_function_type            elf32_arm_is_function_type 
10253
10254 #define elf_backend_can_refcount    1
10255 #define elf_backend_can_gc_sections 1
10256 #define elf_backend_plt_readonly    1
10257 #define elf_backend_want_got_plt    1
10258 #define elf_backend_want_plt_sym    0
10259 #define elf_backend_may_use_rel_p   1
10260 #define elf_backend_may_use_rela_p  0
10261 #define elf_backend_default_use_rela_p 0
10262
10263 #define elf_backend_got_header_size     12
10264
10265 #undef elf_backend_obj_attrs_vendor
10266 #define elf_backend_obj_attrs_vendor    "aeabi"
10267 #undef elf_backend_obj_attrs_section
10268 #define elf_backend_obj_attrs_section   ".ARM.attributes"
10269 #undef elf_backend_obj_attrs_arg_type
10270 #define elf_backend_obj_attrs_arg_type  elf32_arm_obj_attrs_arg_type
10271 #undef elf_backend_obj_attrs_section_type
10272 #define elf_backend_obj_attrs_section_type      SHT_ARM_ATTRIBUTES
10273
10274 #include "elf32-target.h"
10275
10276 /* VxWorks Targets */
10277
10278 #undef TARGET_LITTLE_SYM
10279 #define TARGET_LITTLE_SYM               bfd_elf32_littlearm_vxworks_vec
10280 #undef TARGET_LITTLE_NAME
10281 #define TARGET_LITTLE_NAME              "elf32-littlearm-vxworks"
10282 #undef TARGET_BIG_SYM
10283 #define TARGET_BIG_SYM                  bfd_elf32_bigarm_vxworks_vec
10284 #undef TARGET_BIG_NAME
10285 #define TARGET_BIG_NAME                 "elf32-bigarm-vxworks"
10286
10287 /* Like elf32_arm_link_hash_table_create -- but overrides
10288    appropriately for VxWorks.  */
10289 static struct bfd_link_hash_table *
10290 elf32_arm_vxworks_link_hash_table_create (bfd *abfd)
10291 {
10292   struct bfd_link_hash_table *ret;
10293
10294   ret = elf32_arm_link_hash_table_create (abfd);
10295   if (ret)
10296     {
10297       struct elf32_arm_link_hash_table *htab
10298         = (struct elf32_arm_link_hash_table *) ret;
10299       htab->use_rel = 0;
10300       htab->vxworks_p = 1;
10301     }
10302   return ret;
10303 }     
10304
10305 static void
10306 elf32_arm_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker)
10307 {
10308   elf32_arm_final_write_processing (abfd, linker);
10309   elf_vxworks_final_write_processing (abfd, linker);
10310 }
10311
10312 #undef elf32_bed
10313 #define elf32_bed elf32_arm_vxworks_bed
10314
10315 #undef bfd_elf32_bfd_link_hash_table_create
10316 #define bfd_elf32_bfd_link_hash_table_create \
10317   elf32_arm_vxworks_link_hash_table_create
10318 #undef elf_backend_add_symbol_hook
10319 #define elf_backend_add_symbol_hook \
10320   elf_vxworks_add_symbol_hook
10321 #undef elf_backend_final_write_processing
10322 #define elf_backend_final_write_processing \
10323   elf32_arm_vxworks_final_write_processing
10324 #undef elf_backend_emit_relocs
10325 #define elf_backend_emit_relocs \
10326   elf_vxworks_emit_relocs
10327
10328 #undef elf_backend_may_use_rel_p
10329 #define elf_backend_may_use_rel_p       0
10330 #undef elf_backend_may_use_rela_p
10331 #define elf_backend_may_use_rela_p      1
10332 #undef elf_backend_default_use_rela_p
10333 #define elf_backend_default_use_rela_p  1
10334 #undef elf_backend_want_plt_sym
10335 #define elf_backend_want_plt_sym        1
10336 #undef ELF_MAXPAGESIZE
10337 #define ELF_MAXPAGESIZE                 0x1000
10338
10339 #include "elf32-target.h"
10340
10341
10342 /* Symbian OS Targets */
10343
10344 #undef TARGET_LITTLE_SYM
10345 #define TARGET_LITTLE_SYM               bfd_elf32_littlearm_symbian_vec
10346 #undef TARGET_LITTLE_NAME
10347 #define TARGET_LITTLE_NAME              "elf32-littlearm-symbian"
10348 #undef TARGET_BIG_SYM
10349 #define TARGET_BIG_SYM                  bfd_elf32_bigarm_symbian_vec
10350 #undef TARGET_BIG_NAME
10351 #define TARGET_BIG_NAME                 "elf32-bigarm-symbian"
10352
10353 /* Like elf32_arm_link_hash_table_create -- but overrides
10354    appropriately for Symbian OS.  */
10355 static struct bfd_link_hash_table *
10356 elf32_arm_symbian_link_hash_table_create (bfd *abfd)
10357 {
10358   struct bfd_link_hash_table *ret;
10359
10360   ret = elf32_arm_link_hash_table_create (abfd);
10361   if (ret)
10362     {
10363       struct elf32_arm_link_hash_table *htab
10364         = (struct elf32_arm_link_hash_table *)ret;
10365       /* There is no PLT header for Symbian OS.  */
10366       htab->plt_header_size = 0;
10367       /* The PLT entries are each three instructions.  */
10368       htab->plt_entry_size = 4 * NUM_ELEM (elf32_arm_symbian_plt_entry);
10369       htab->symbian_p = 1;
10370       /* Symbian uses armv5t or above, so use_blx is always true.  */
10371       htab->use_blx = 1;
10372       htab->root.is_relocatable_executable = 1;
10373     }
10374   return ret;
10375 }     
10376
10377 static const struct bfd_elf_special_section
10378 elf32_arm_symbian_special_sections[] =
10379 {
10380   /* In a BPABI executable, the dynamic linking sections do not go in
10381      the loadable read-only segment.  The post-linker may wish to
10382      refer to these sections, but they are not part of the final
10383      program image.  */
10384   { STRING_COMMA_LEN (".dynamic"),       0, SHT_DYNAMIC,  0 },
10385   { STRING_COMMA_LEN (".dynstr"),        0, SHT_STRTAB,   0 },
10386   { STRING_COMMA_LEN (".dynsym"),        0, SHT_DYNSYM,   0 },
10387   { STRING_COMMA_LEN (".got"),           0, SHT_PROGBITS, 0 },
10388   { STRING_COMMA_LEN (".hash"),          0, SHT_HASH,     0 },
10389   /* These sections do not need to be writable as the SymbianOS
10390      postlinker will arrange things so that no dynamic relocation is
10391      required.  */
10392   { STRING_COMMA_LEN (".init_array"),    0, SHT_INIT_ARRAY,    SHF_ALLOC },
10393   { STRING_COMMA_LEN (".fini_array"),    0, SHT_FINI_ARRAY,    SHF_ALLOC },
10394   { STRING_COMMA_LEN (".preinit_array"), 0, SHT_PREINIT_ARRAY, SHF_ALLOC },
10395   { NULL,                             0, 0, 0,                 0 }
10396 };
10397
10398 static void
10399 elf32_arm_symbian_begin_write_processing (bfd *abfd, 
10400                                           struct bfd_link_info *link_info)
10401 {
10402   /* BPABI objects are never loaded directly by an OS kernel; they are
10403      processed by a postlinker first, into an OS-specific format.  If
10404      the D_PAGED bit is set on the file, BFD will align segments on
10405      page boundaries, so that an OS can directly map the file.  With
10406      BPABI objects, that just results in wasted space.  In addition,
10407      because we clear the D_PAGED bit, map_sections_to_segments will
10408      recognize that the program headers should not be mapped into any
10409      loadable segment.  */
10410   abfd->flags &= ~D_PAGED;
10411   elf32_arm_begin_write_processing(abfd, link_info);
10412 }
10413
10414 static bfd_boolean
10415 elf32_arm_symbian_modify_segment_map (bfd *abfd, 
10416                                       struct bfd_link_info *info)
10417 {
10418   struct elf_segment_map *m;
10419   asection *dynsec;
10420
10421   /* BPABI shared libraries and executables should have a PT_DYNAMIC
10422      segment.  However, because the .dynamic section is not marked
10423      with SEC_LOAD, the generic ELF code will not create such a
10424      segment.  */
10425   dynsec = bfd_get_section_by_name (abfd, ".dynamic");
10426   if (dynsec)
10427     {
10428       for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
10429         if (m->p_type == PT_DYNAMIC)
10430           break;
10431
10432       if (m == NULL)
10433         {
10434           m = _bfd_elf_make_dynamic_segment (abfd, dynsec);
10435           m->next = elf_tdata (abfd)->segment_map;
10436           elf_tdata (abfd)->segment_map = m;
10437         }
10438     }
10439
10440   /* Also call the generic arm routine.  */
10441   return elf32_arm_modify_segment_map (abfd, info);
10442 }
10443
10444 #undef elf32_bed
10445 #define elf32_bed elf32_arm_symbian_bed
10446
10447 /* The dynamic sections are not allocated on SymbianOS; the postlinker
10448    will process them and then discard them.  */
10449 #undef ELF_DYNAMIC_SEC_FLAGS
10450 #define ELF_DYNAMIC_SEC_FLAGS \
10451   (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED)
10452
10453 #undef bfd_elf32_bfd_link_hash_table_create
10454 #define bfd_elf32_bfd_link_hash_table_create \
10455   elf32_arm_symbian_link_hash_table_create
10456 #undef elf_backend_add_symbol_hook
10457
10458 #undef elf_backend_special_sections
10459 #define elf_backend_special_sections elf32_arm_symbian_special_sections
10460
10461 #undef elf_backend_begin_write_processing
10462 #define elf_backend_begin_write_processing \
10463     elf32_arm_symbian_begin_write_processing
10464 #undef elf_backend_final_write_processing
10465 #define elf_backend_final_write_processing \
10466   elf32_arm_final_write_processing
10467 #undef elf_backend_emit_relocs
10468
10469 #undef elf_backend_modify_segment_map
10470 #define elf_backend_modify_segment_map elf32_arm_symbian_modify_segment_map
10471
10472 /* There is no .got section for BPABI objects, and hence no header.  */
10473 #undef elf_backend_got_header_size
10474 #define elf_backend_got_header_size 0
10475
10476 /* Similarly, there is no .got.plt section.  */
10477 #undef elf_backend_want_got_plt
10478 #define elf_backend_want_got_plt 0
10479
10480 #undef elf_backend_may_use_rel_p
10481 #define elf_backend_may_use_rel_p       1
10482 #undef elf_backend_may_use_rela_p
10483 #define elf_backend_may_use_rela_p      0
10484 #undef elf_backend_default_use_rela_p
10485 #define elf_backend_default_use_rela_p  0
10486 #undef elf_backend_want_plt_sym
10487 #define elf_backend_want_plt_sym        0
10488 #undef ELF_MAXPAGESIZE
10489 #define ELF_MAXPAGESIZE                 0x8000
10490
10491 #include "elf32-target.h"