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