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