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