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