]>
Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* 32-bit ELF support for ARM |
d1f161ea NC |
2 | Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004 |
3 | Free Software Foundation, Inc. | |
252b5132 RH |
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
20 | ||
acf8aed4 AM |
21 | #ifndef USE_REL |
22 | #define USE_REL 0 | |
23 | #endif | |
24 | ||
252b5132 RH |
25 | typedef unsigned long int insn32; |
26 | typedef unsigned short int insn16; | |
27 | ||
85a84e7a | 28 | /* In leiu of proper flags, assume all EABIv3 objects are interworkable. */ |
57e8b36a | 29 | #define INTERWORK_FLAG(abfd) \ |
85a84e7a PB |
30 | (EF_ARM_EABI_VERSION (elf_elfheader (abfd)->e_flags) == EF_ARM_EABI_VER3 \ |
31 | || (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK)) | |
9b485d32 | 32 | |
252b5132 RH |
33 | /* The linker script knows the section names for placement. |
34 | The entry_names are used to do simple name mangling on the stubs. | |
35 | Given a function name, and its type, the stub can be found. The | |
9b485d32 | 36 | name can be changed. The only requirement is the %s be present. */ |
252b5132 RH |
37 | #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t" |
38 | #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb" | |
39 | ||
40 | #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7" | |
41 | #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm" | |
42 | ||
43 | /* The name of the dynamic interpreter. This is put in the .interp | |
44 | section. */ | |
45 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1" | |
46 | ||
5e681ec4 PB |
47 | #ifdef FOUR_WORD_PLT |
48 | ||
252b5132 RH |
49 | /* The first entry in a procedure linkage table looks like |
50 | this. It is set up so that any shared library function that is | |
59f2c4e7 | 51 | called before the relocation has been set up calls the dynamic |
9b485d32 | 52 | linker first. */ |
e5a52504 | 53 | static const bfd_vma elf32_arm_plt0_entry [] = |
5e681ec4 PB |
54 | { |
55 | 0xe52de004, /* str lr, [sp, #-4]! */ | |
56 | 0xe59fe010, /* ldr lr, [pc, #16] */ | |
57 | 0xe08fe00e, /* add lr, pc, lr */ | |
58 | 0xe5bef008, /* ldr pc, [lr, #8]! */ | |
59 | }; | |
60 | ||
61 | /* Subsequent entries in a procedure linkage table look like | |
62 | this. */ | |
e5a52504 | 63 | static const bfd_vma elf32_arm_plt_entry [] = |
5e681ec4 PB |
64 | { |
65 | 0xe28fc600, /* add ip, pc, #NN */ | |
66 | 0xe28cca00, /* add ip, ip, #NN */ | |
67 | 0xe5bcf000, /* ldr pc, [ip, #NN]! */ | |
68 | 0x00000000, /* unused */ | |
69 | }; | |
70 | ||
71 | #else | |
72 | ||
5e681ec4 PB |
73 | /* The first entry in a procedure linkage table looks like |
74 | this. It is set up so that any shared library function that is | |
75 | called before the relocation has been set up calls the dynamic | |
76 | linker first. */ | |
e5a52504 | 77 | static const bfd_vma elf32_arm_plt0_entry [] = |
917583ad | 78 | { |
5e681ec4 PB |
79 | 0xe52de004, /* str lr, [sp, #-4]! */ |
80 | 0xe59fe004, /* ldr lr, [pc, #4] */ | |
81 | 0xe08fe00e, /* add lr, pc, lr */ | |
82 | 0xe5bef008, /* ldr pc, [lr, #8]! */ | |
83 | 0x00000000, /* &GOT[0] - . */ | |
917583ad | 84 | }; |
252b5132 RH |
85 | |
86 | /* Subsequent entries in a procedure linkage table look like | |
87 | this. */ | |
e5a52504 | 88 | static const bfd_vma elf32_arm_plt_entry [] = |
5e681ec4 PB |
89 | { |
90 | 0xe28fc600, /* add ip, pc, #0xNN00000 */ | |
91 | 0xe28cca00, /* add ip, ip, #0xNN000 */ | |
92 | 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */ | |
93 | }; | |
94 | ||
95 | #endif | |
252b5132 | 96 | |
e5a52504 MM |
97 | /* The entries in a PLT when using a DLL-based target with multiple |
98 | address spaces. */ | |
99 | static const bfd_vma elf32_arm_symbian_plt_entry [] = | |
100 | { | |
101 | 0xe51ff004, /* ldr pr, [pc, #-4] */ | |
102 | 0x00000000, /* dcd R_ARM_GLOB_DAT(X) */ | |
103 | }; | |
104 | ||
e489d0ae PB |
105 | /* Used to build a map of a section. This is required for mixed-endian |
106 | code/data. */ | |
107 | ||
108 | typedef struct elf32_elf_section_map | |
109 | { | |
110 | bfd_vma vma; | |
111 | char type; | |
112 | } | |
113 | elf32_arm_section_map; | |
114 | ||
115 | struct _arm_elf_section_data | |
116 | { | |
117 | struct bfd_elf_section_data elf; | |
118 | int mapcount; | |
119 | elf32_arm_section_map *map; | |
120 | }; | |
121 | ||
122 | #define elf32_arm_section_data(sec) \ | |
123 | ((struct _arm_elf_section_data *) elf_section_data (sec)) | |
124 | ||
252b5132 RH |
125 | /* The ARM linker needs to keep track of the number of relocs that it |
126 | decides to copy in check_relocs for each symbol. This is so that | |
127 | it can discard PC relative relocs if it doesn't need them when | |
128 | linking with -Bsymbolic. We store the information in a field | |
129 | extending the regular ELF linker hash table. */ | |
130 | ||
131 | /* This structure keeps track of the number of PC relative relocs we | |
132 | have copied for a given symbol. */ | |
5e681ec4 | 133 | struct elf32_arm_relocs_copied |
917583ad NC |
134 | { |
135 | /* Next section. */ | |
5e681ec4 | 136 | struct elf32_arm_relocs_copied * next; |
917583ad NC |
137 | /* A section in dynobj. */ |
138 | asection * section; | |
139 | /* Number of relocs copied in this section. */ | |
140 | bfd_size_type count; | |
141 | }; | |
252b5132 | 142 | |
ba96a88f | 143 | /* Arm ELF linker hash entry. */ |
252b5132 | 144 | struct elf32_arm_link_hash_entry |
917583ad NC |
145 | { |
146 | struct elf_link_hash_entry root; | |
252b5132 | 147 | |
917583ad | 148 | /* Number of PC relative relocs copied for this symbol. */ |
5e681ec4 | 149 | struct elf32_arm_relocs_copied * relocs_copied; |
917583ad | 150 | }; |
252b5132 | 151 | |
252b5132 | 152 | /* Traverse an arm ELF linker hash table. */ |
252b5132 RH |
153 | #define elf32_arm_link_hash_traverse(table, func, info) \ |
154 | (elf_link_hash_traverse \ | |
155 | (&(table)->root, \ | |
57e8b36a | 156 | (bfd_boolean (*) (struct elf_link_hash_entry *, void *))) (func), \ |
252b5132 RH |
157 | (info))) |
158 | ||
159 | /* Get the ARM elf linker hash table from a link_info structure. */ | |
160 | #define elf32_arm_hash_table(info) \ | |
161 | ((struct elf32_arm_link_hash_table *) ((info)->hash)) | |
162 | ||
9b485d32 | 163 | /* ARM ELF linker hash table. */ |
252b5132 | 164 | struct elf32_arm_link_hash_table |
917583ad NC |
165 | { |
166 | /* The main hash table. */ | |
167 | struct elf_link_hash_table root; | |
252b5132 | 168 | |
4cc11e76 | 169 | /* The size in bytes of the section containing the Thumb-to-ARM glue. */ |
dc810e39 | 170 | bfd_size_type thumb_glue_size; |
252b5132 | 171 | |
4cc11e76 | 172 | /* The size in bytes of the section containing the ARM-to-Thumb glue. */ |
dc810e39 | 173 | bfd_size_type arm_glue_size; |
252b5132 | 174 | |
4cc11e76 | 175 | /* An arbitrary input BFD chosen to hold the glue sections. */ |
917583ad | 176 | bfd * bfd_of_glue_owner; |
ba96a88f | 177 | |
917583ad NC |
178 | /* A boolean indicating whether knowledge of the ARM's pipeline |
179 | length should be applied by the linker. */ | |
180 | int no_pipeline_knowledge; | |
5e681ec4 | 181 | |
e489d0ae PB |
182 | /* Nonzero to output a BE8 image. */ |
183 | int byteswap_code; | |
184 | ||
e5a52504 MM |
185 | /* The number of bytes in the initial entry in the PLT. */ |
186 | bfd_size_type plt_header_size; | |
187 | ||
188 | /* The number of bytes in the subsequent PLT etries. */ | |
189 | bfd_size_type plt_entry_size; | |
190 | ||
191 | /* True if the target system is Symbian OS. */ | |
192 | int symbian_p; | |
193 | ||
5e681ec4 PB |
194 | /* Short-cuts to get to dynamic linker sections. */ |
195 | asection *sgot; | |
196 | asection *sgotplt; | |
197 | asection *srelgot; | |
198 | asection *splt; | |
199 | asection *srelplt; | |
200 | asection *sdynbss; | |
201 | asection *srelbss; | |
202 | ||
203 | /* Small local sym to section mapping cache. */ | |
204 | struct sym_sec_cache sym_sec; | |
917583ad | 205 | }; |
252b5132 | 206 | |
780a67af NC |
207 | /* Create an entry in an ARM ELF linker hash table. */ |
208 | ||
209 | static struct bfd_hash_entry * | |
57e8b36a NC |
210 | elf32_arm_link_hash_newfunc (struct bfd_hash_entry * entry, |
211 | struct bfd_hash_table * table, | |
212 | const char * string) | |
780a67af NC |
213 | { |
214 | struct elf32_arm_link_hash_entry * ret = | |
215 | (struct elf32_arm_link_hash_entry *) entry; | |
216 | ||
217 | /* Allocate the structure if it has not already been allocated by a | |
218 | subclass. */ | |
219 | if (ret == (struct elf32_arm_link_hash_entry *) NULL) | |
57e8b36a NC |
220 | ret = bfd_hash_allocate (table, sizeof (struct elf32_arm_link_hash_entry)); |
221 | if (ret == NULL) | |
780a67af NC |
222 | return (struct bfd_hash_entry *) ret; |
223 | ||
224 | /* Call the allocation method of the superclass. */ | |
225 | ret = ((struct elf32_arm_link_hash_entry *) | |
226 | _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret, | |
227 | table, string)); | |
57e8b36a | 228 | if (ret != NULL) |
5e681ec4 | 229 | ret->relocs_copied = NULL; |
780a67af NC |
230 | |
231 | return (struct bfd_hash_entry *) ret; | |
232 | } | |
233 | ||
5e681ec4 PB |
234 | /* Create .got, .gotplt, and .rel.got sections in DYNOBJ, and set up |
235 | shortcuts to them in our hash table. */ | |
236 | ||
237 | static bfd_boolean | |
57e8b36a | 238 | create_got_section (bfd *dynobj, struct bfd_link_info *info) |
5e681ec4 PB |
239 | { |
240 | struct elf32_arm_link_hash_table *htab; | |
241 | ||
e5a52504 MM |
242 | htab = elf32_arm_hash_table (info); |
243 | /* BPABI objects never have a GOT, or associated sections. */ | |
244 | if (htab->symbian_p) | |
245 | return TRUE; | |
246 | ||
5e681ec4 PB |
247 | if (! _bfd_elf_create_got_section (dynobj, info)) |
248 | return FALSE; | |
249 | ||
5e681ec4 PB |
250 | htab->sgot = bfd_get_section_by_name (dynobj, ".got"); |
251 | htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt"); | |
252 | if (!htab->sgot || !htab->sgotplt) | |
253 | abort (); | |
254 | ||
255 | htab->srelgot = bfd_make_section (dynobj, ".rel.got"); | |
256 | if (htab->srelgot == NULL | |
257 | || ! bfd_set_section_flags (dynobj, htab->srelgot, | |
258 | (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | |
259 | | SEC_IN_MEMORY | SEC_LINKER_CREATED | |
260 | | SEC_READONLY)) | |
261 | || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2)) | |
262 | return FALSE; | |
263 | return TRUE; | |
264 | } | |
265 | ||
266 | /* Create .plt, .rel.plt, .got, .got.plt, .rel.got, .dynbss, and | |
267 | .rel.bss sections in DYNOBJ, and set up shortcuts to them in our | |
268 | hash table. */ | |
269 | ||
270 | static bfd_boolean | |
57e8b36a | 271 | elf32_arm_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info) |
5e681ec4 PB |
272 | { |
273 | struct elf32_arm_link_hash_table *htab; | |
274 | ||
275 | htab = elf32_arm_hash_table (info); | |
276 | if (!htab->sgot && !create_got_section (dynobj, info)) | |
277 | return FALSE; | |
278 | ||
279 | if (!_bfd_elf_create_dynamic_sections (dynobj, info)) | |
280 | return FALSE; | |
281 | ||
282 | htab->splt = bfd_get_section_by_name (dynobj, ".plt"); | |
283 | htab->srelplt = bfd_get_section_by_name (dynobj, ".rel.plt"); | |
284 | htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss"); | |
285 | if (!info->shared) | |
286 | htab->srelbss = bfd_get_section_by_name (dynobj, ".rel.bss"); | |
287 | ||
e5a52504 MM |
288 | if (!htab->splt |
289 | || !htab->srelplt | |
290 | || !htab->sdynbss | |
5e681ec4 PB |
291 | || (!info->shared && !htab->srelbss)) |
292 | abort (); | |
293 | ||
294 | return TRUE; | |
295 | } | |
296 | ||
297 | /* Copy the extra info we tack onto an elf_link_hash_entry. */ | |
298 | ||
299 | static void | |
300 | elf32_arm_copy_indirect_symbol (const struct elf_backend_data *bed, | |
301 | struct elf_link_hash_entry *dir, | |
302 | struct elf_link_hash_entry *ind) | |
303 | { | |
304 | struct elf32_arm_link_hash_entry *edir, *eind; | |
305 | ||
306 | edir = (struct elf32_arm_link_hash_entry *) dir; | |
307 | eind = (struct elf32_arm_link_hash_entry *) ind; | |
308 | ||
309 | if (eind->relocs_copied != NULL) | |
310 | { | |
311 | if (edir->relocs_copied != NULL) | |
312 | { | |
313 | struct elf32_arm_relocs_copied **pp; | |
314 | struct elf32_arm_relocs_copied *p; | |
315 | ||
316 | if (ind->root.type == bfd_link_hash_indirect) | |
317 | abort (); | |
318 | ||
319 | /* Add reloc counts against the weak sym to the strong sym | |
320 | list. Merge any entries against the same section. */ | |
321 | for (pp = &eind->relocs_copied; (p = *pp) != NULL; ) | |
322 | { | |
323 | struct elf32_arm_relocs_copied *q; | |
324 | ||
325 | for (q = edir->relocs_copied; q != NULL; q = q->next) | |
326 | if (q->section == p->section) | |
327 | { | |
5e681ec4 PB |
328 | q->count += p->count; |
329 | *pp = p->next; | |
330 | break; | |
331 | } | |
332 | if (q == NULL) | |
333 | pp = &p->next; | |
334 | } | |
335 | *pp = edir->relocs_copied; | |
336 | } | |
337 | ||
338 | edir->relocs_copied = eind->relocs_copied; | |
339 | eind->relocs_copied = NULL; | |
340 | } | |
341 | ||
342 | _bfd_elf_link_hash_copy_indirect (bed, dir, ind); | |
343 | } | |
344 | ||
9b485d32 | 345 | /* Create an ARM elf linker hash table. */ |
252b5132 RH |
346 | |
347 | static struct bfd_link_hash_table * | |
57e8b36a | 348 | elf32_arm_link_hash_table_create (bfd *abfd) |
252b5132 RH |
349 | { |
350 | struct elf32_arm_link_hash_table *ret; | |
dc810e39 | 351 | bfd_size_type amt = sizeof (struct elf32_arm_link_hash_table); |
252b5132 | 352 | |
57e8b36a NC |
353 | ret = bfd_malloc (amt); |
354 | if (ret == NULL) | |
252b5132 RH |
355 | return NULL; |
356 | ||
57e8b36a | 357 | if (!_bfd_elf_link_hash_table_init (& ret->root, abfd, |
780a67af | 358 | elf32_arm_link_hash_newfunc)) |
252b5132 | 359 | { |
e2d34d7d | 360 | free (ret); |
252b5132 RH |
361 | return NULL; |
362 | } | |
363 | ||
5e681ec4 PB |
364 | ret->sgot = NULL; |
365 | ret->sgotplt = NULL; | |
366 | ret->srelgot = NULL; | |
367 | ret->splt = NULL; | |
368 | ret->srelplt = NULL; | |
369 | ret->sdynbss = NULL; | |
370 | ret->srelbss = NULL; | |
252b5132 RH |
371 | ret->thumb_glue_size = 0; |
372 | ret->arm_glue_size = 0; | |
373 | ret->bfd_of_glue_owner = NULL; | |
ba96a88f | 374 | ret->no_pipeline_knowledge = 0; |
e489d0ae | 375 | ret->byteswap_code = 0; |
e5a52504 MM |
376 | #ifdef FOUR_WORD_PLT |
377 | ret->plt_header_size = 16; | |
378 | ret->plt_entry_size = 16; | |
379 | #else | |
380 | ret->plt_header_size = 20; | |
381 | ret->plt_entry_size = 12; | |
382 | #endif | |
383 | ret->symbian_p = 0; | |
5e681ec4 | 384 | ret->sym_sec.abfd = NULL; |
252b5132 RH |
385 | |
386 | return &ret->root.root; | |
387 | } | |
388 | ||
9b485d32 NC |
389 | /* Locate the Thumb encoded calling stub for NAME. */ |
390 | ||
252b5132 | 391 | static struct elf_link_hash_entry * |
57e8b36a NC |
392 | find_thumb_glue (struct bfd_link_info *link_info, |
393 | const char *name, | |
394 | bfd *input_bfd) | |
252b5132 RH |
395 | { |
396 | char *tmp_name; | |
397 | struct elf_link_hash_entry *hash; | |
398 | struct elf32_arm_link_hash_table *hash_table; | |
399 | ||
400 | /* We need a pointer to the armelf specific hash table. */ | |
401 | hash_table = elf32_arm_hash_table (link_info); | |
402 | ||
57e8b36a NC |
403 | tmp_name = bfd_malloc ((bfd_size_type) strlen (name) |
404 | + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1); | |
252b5132 RH |
405 | |
406 | BFD_ASSERT (tmp_name); | |
407 | ||
408 | sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name); | |
409 | ||
410 | hash = elf_link_hash_lookup | |
b34976b6 | 411 | (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE); |
252b5132 RH |
412 | |
413 | if (hash == NULL) | |
414 | /* xgettext:c-format */ | |
d003868e AM |
415 | (*_bfd_error_handler) (_("%B: unable to find THUMB glue '%s' for `%s'"), |
416 | input_bfd, tmp_name, name); | |
252b5132 RH |
417 | |
418 | free (tmp_name); | |
419 | ||
420 | return hash; | |
421 | } | |
422 | ||
9b485d32 NC |
423 | /* Locate the ARM encoded calling stub for NAME. */ |
424 | ||
252b5132 | 425 | static struct elf_link_hash_entry * |
57e8b36a NC |
426 | find_arm_glue (struct bfd_link_info *link_info, |
427 | const char *name, | |
428 | bfd *input_bfd) | |
252b5132 RH |
429 | { |
430 | char *tmp_name; | |
431 | struct elf_link_hash_entry *myh; | |
432 | struct elf32_arm_link_hash_table *hash_table; | |
433 | ||
434 | /* We need a pointer to the elfarm specific hash table. */ | |
435 | hash_table = elf32_arm_hash_table (link_info); | |
436 | ||
57e8b36a NC |
437 | tmp_name = bfd_malloc ((bfd_size_type) strlen (name) |
438 | + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1); | |
252b5132 RH |
439 | |
440 | BFD_ASSERT (tmp_name); | |
441 | ||
442 | sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name); | |
443 | ||
444 | myh = elf_link_hash_lookup | |
b34976b6 | 445 | (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE); |
252b5132 RH |
446 | |
447 | if (myh == NULL) | |
448 | /* xgettext:c-format */ | |
d003868e AM |
449 | (*_bfd_error_handler) (_("%B: unable to find ARM glue '%s' for `%s'"), |
450 | input_bfd, tmp_name, name); | |
252b5132 RH |
451 | |
452 | free (tmp_name); | |
453 | ||
454 | return myh; | |
455 | } | |
456 | ||
9b485d32 | 457 | /* ARM->Thumb glue: |
252b5132 RH |
458 | |
459 | .arm | |
460 | __func_from_arm: | |
461 | ldr r12, __func_addr | |
462 | bx r12 | |
463 | __func_addr: | |
9b485d32 | 464 | .word func @ behave as if you saw a ARM_32 reloc. */ |
252b5132 RH |
465 | |
466 | #define ARM2THUMB_GLUE_SIZE 12 | |
467 | static const insn32 a2t1_ldr_insn = 0xe59fc000; | |
468 | static const insn32 a2t2_bx_r12_insn = 0xe12fff1c; | |
469 | static const insn32 a2t3_func_addr_insn = 0x00000001; | |
470 | ||
9b485d32 | 471 | /* Thumb->ARM: Thumb->(non-interworking aware) ARM |
252b5132 RH |
472 | |
473 | .thumb .thumb | |
474 | .align 2 .align 2 | |
475 | __func_from_thumb: __func_from_thumb: | |
476 | bx pc push {r6, lr} | |
477 | nop ldr r6, __func_addr | |
478 | .arm mov lr, pc | |
479 | __func_change_to_arm: bx r6 | |
480 | b func .arm | |
481 | __func_back_to_thumb: | |
482 | ldmia r13! {r6, lr} | |
483 | bx lr | |
484 | __func_addr: | |
9b485d32 | 485 | .word func */ |
252b5132 RH |
486 | |
487 | #define THUMB2ARM_GLUE_SIZE 8 | |
488 | static const insn16 t2a1_bx_pc_insn = 0x4778; | |
489 | static const insn16 t2a2_noop_insn = 0x46c0; | |
490 | static const insn32 t2a3_b_insn = 0xea000000; | |
491 | ||
7e392df6 | 492 | #ifndef ELFARM_NABI_C_INCLUDED |
b34976b6 | 493 | bfd_boolean |
57e8b36a | 494 | bfd_elf32_arm_allocate_interworking_sections (struct bfd_link_info * info) |
252b5132 RH |
495 | { |
496 | asection * s; | |
497 | bfd_byte * foo; | |
498 | struct elf32_arm_link_hash_table * globals; | |
499 | ||
500 | globals = elf32_arm_hash_table (info); | |
501 | ||
502 | BFD_ASSERT (globals != NULL); | |
503 | ||
504 | if (globals->arm_glue_size != 0) | |
505 | { | |
506 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); | |
507 | ||
dc810e39 AM |
508 | s = bfd_get_section_by_name (globals->bfd_of_glue_owner, |
509 | ARM2THUMB_GLUE_SECTION_NAME); | |
252b5132 RH |
510 | |
511 | BFD_ASSERT (s != NULL); | |
512 | ||
57e8b36a | 513 | foo = bfd_alloc (globals->bfd_of_glue_owner, globals->arm_glue_size); |
252b5132 | 514 | |
eea6121a | 515 | s->size = globals->arm_glue_size; |
252b5132 RH |
516 | s->contents = foo; |
517 | } | |
518 | ||
519 | if (globals->thumb_glue_size != 0) | |
520 | { | |
521 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); | |
522 | ||
523 | s = bfd_get_section_by_name | |
524 | (globals->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME); | |
525 | ||
526 | BFD_ASSERT (s != NULL); | |
527 | ||
57e8b36a | 528 | foo = bfd_alloc (globals->bfd_of_glue_owner, globals->thumb_glue_size); |
252b5132 | 529 | |
eea6121a | 530 | s->size = globals->thumb_glue_size; |
252b5132 RH |
531 | s->contents = foo; |
532 | } | |
533 | ||
b34976b6 | 534 | return TRUE; |
252b5132 RH |
535 | } |
536 | ||
537 | static void | |
57e8b36a NC |
538 | record_arm_to_thumb_glue (struct bfd_link_info * link_info, |
539 | struct elf_link_hash_entry * h) | |
252b5132 RH |
540 | { |
541 | const char * name = h->root.root.string; | |
63b0f745 | 542 | asection * s; |
252b5132 RH |
543 | char * tmp_name; |
544 | struct elf_link_hash_entry * myh; | |
14a793b2 | 545 | struct bfd_link_hash_entry * bh; |
252b5132 | 546 | struct elf32_arm_link_hash_table * globals; |
dc810e39 | 547 | bfd_vma val; |
252b5132 RH |
548 | |
549 | globals = elf32_arm_hash_table (link_info); | |
550 | ||
551 | BFD_ASSERT (globals != NULL); | |
552 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); | |
553 | ||
554 | s = bfd_get_section_by_name | |
555 | (globals->bfd_of_glue_owner, ARM2THUMB_GLUE_SECTION_NAME); | |
556 | ||
252b5132 RH |
557 | BFD_ASSERT (s != NULL); |
558 | ||
57e8b36a | 559 | tmp_name = bfd_malloc ((bfd_size_type) strlen (name) + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1); |
252b5132 RH |
560 | |
561 | BFD_ASSERT (tmp_name); | |
562 | ||
563 | sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name); | |
564 | ||
565 | myh = elf_link_hash_lookup | |
b34976b6 | 566 | (&(globals)->root, tmp_name, FALSE, FALSE, TRUE); |
252b5132 RH |
567 | |
568 | if (myh != NULL) | |
569 | { | |
9b485d32 | 570 | /* We've already seen this guy. */ |
252b5132 | 571 | free (tmp_name); |
9b485d32 | 572 | return; |
252b5132 RH |
573 | } |
574 | ||
57e8b36a NC |
575 | /* The only trick here is using hash_table->arm_glue_size as the value. |
576 | Even though the section isn't allocated yet, this is where we will be | |
577 | putting it. */ | |
14a793b2 | 578 | bh = NULL; |
dc810e39 AM |
579 | val = globals->arm_glue_size + 1; |
580 | _bfd_generic_link_add_one_symbol (link_info, globals->bfd_of_glue_owner, | |
581 | tmp_name, BSF_GLOBAL, s, val, | |
b34976b6 | 582 | NULL, TRUE, FALSE, &bh); |
252b5132 RH |
583 | |
584 | free (tmp_name); | |
585 | ||
586 | globals->arm_glue_size += ARM2THUMB_GLUE_SIZE; | |
587 | ||
588 | return; | |
589 | } | |
590 | ||
591 | static void | |
57e8b36a NC |
592 | record_thumb_to_arm_glue (struct bfd_link_info *link_info, |
593 | struct elf_link_hash_entry *h) | |
252b5132 RH |
594 | { |
595 | const char *name = h->root.root.string; | |
63b0f745 | 596 | asection *s; |
252b5132 RH |
597 | char *tmp_name; |
598 | struct elf_link_hash_entry *myh; | |
14a793b2 | 599 | struct bfd_link_hash_entry *bh; |
252b5132 RH |
600 | struct elf32_arm_link_hash_table *hash_table; |
601 | char bind; | |
dc810e39 | 602 | bfd_vma val; |
252b5132 RH |
603 | |
604 | hash_table = elf32_arm_hash_table (link_info); | |
605 | ||
606 | BFD_ASSERT (hash_table != NULL); | |
607 | BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL); | |
608 | ||
609 | s = bfd_get_section_by_name | |
610 | (hash_table->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME); | |
611 | ||
612 | BFD_ASSERT (s != NULL); | |
613 | ||
57e8b36a NC |
614 | tmp_name = bfd_malloc ((bfd_size_type) strlen (name) |
615 | + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1); | |
252b5132 RH |
616 | |
617 | BFD_ASSERT (tmp_name); | |
618 | ||
619 | sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name); | |
620 | ||
621 | myh = elf_link_hash_lookup | |
b34976b6 | 622 | (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE); |
252b5132 RH |
623 | |
624 | if (myh != NULL) | |
625 | { | |
9b485d32 | 626 | /* We've already seen this guy. */ |
252b5132 | 627 | free (tmp_name); |
9b485d32 | 628 | return; |
252b5132 RH |
629 | } |
630 | ||
14a793b2 | 631 | bh = NULL; |
dc810e39 AM |
632 | val = hash_table->thumb_glue_size + 1; |
633 | _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner, | |
634 | tmp_name, BSF_GLOBAL, s, val, | |
b34976b6 | 635 | NULL, TRUE, FALSE, &bh); |
252b5132 | 636 | |
9b485d32 | 637 | /* If we mark it 'Thumb', the disassembler will do a better job. */ |
14a793b2 | 638 | myh = (struct elf_link_hash_entry *) bh; |
252b5132 RH |
639 | bind = ELF_ST_BIND (myh->type); |
640 | myh->type = ELF_ST_INFO (bind, STT_ARM_TFUNC); | |
641 | ||
642 | free (tmp_name); | |
643 | ||
252b5132 RH |
644 | #define CHANGE_TO_ARM "__%s_change_to_arm" |
645 | #define BACK_FROM_ARM "__%s_back_from_arm" | |
646 | ||
9b485d32 | 647 | /* Allocate another symbol to mark where we switch to Arm mode. */ |
57e8b36a NC |
648 | tmp_name = bfd_malloc ((bfd_size_type) strlen (name) |
649 | + strlen (CHANGE_TO_ARM) + 1); | |
252b5132 RH |
650 | |
651 | BFD_ASSERT (tmp_name); | |
652 | ||
653 | sprintf (tmp_name, CHANGE_TO_ARM, name); | |
654 | ||
14a793b2 | 655 | bh = NULL; |
dc810e39 AM |
656 | val = hash_table->thumb_glue_size + 4, |
657 | _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner, | |
658 | tmp_name, BSF_LOCAL, s, val, | |
b34976b6 | 659 | NULL, TRUE, FALSE, &bh); |
252b5132 RH |
660 | |
661 | free (tmp_name); | |
662 | ||
663 | hash_table->thumb_glue_size += THUMB2ARM_GLUE_SIZE; | |
664 | ||
665 | return; | |
666 | } | |
667 | ||
8afb0e02 NC |
668 | /* Add the glue sections to ABFD. This function is called from the |
669 | linker scripts in ld/emultempl/{armelf}.em. */ | |
9b485d32 | 670 | |
b34976b6 | 671 | bfd_boolean |
57e8b36a NC |
672 | bfd_elf32_arm_add_glue_sections_to_bfd (bfd *abfd, |
673 | struct bfd_link_info *info) | |
252b5132 | 674 | { |
252b5132 RH |
675 | flagword flags; |
676 | asection *sec; | |
677 | ||
8afb0e02 NC |
678 | /* If we are only performing a partial |
679 | link do not bother adding the glue. */ | |
1049f94e | 680 | if (info->relocatable) |
b34976b6 | 681 | return TRUE; |
252b5132 | 682 | |
252b5132 RH |
683 | sec = bfd_get_section_by_name (abfd, ARM2THUMB_GLUE_SECTION_NAME); |
684 | ||
685 | if (sec == NULL) | |
686 | { | |
57db232e NC |
687 | /* Note: we do not include the flag SEC_LINKER_CREATED, as this |
688 | will prevent elf_link_input_bfd() from processing the contents | |
689 | of this section. */ | |
811b4bf6 | 690 | flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_CODE | SEC_READONLY; |
252b5132 RH |
691 | |
692 | sec = bfd_make_section (abfd, ARM2THUMB_GLUE_SECTION_NAME); | |
693 | ||
694 | if (sec == NULL | |
695 | || !bfd_set_section_flags (abfd, sec, flags) | |
696 | || !bfd_set_section_alignment (abfd, sec, 2)) | |
b34976b6 | 697 | return FALSE; |
9a5aca8c | 698 | |
57db232e NC |
699 | /* Set the gc mark to prevent the section from being removed by garbage |
700 | collection, despite the fact that no relocs refer to this section. */ | |
701 | sec->gc_mark = 1; | |
252b5132 RH |
702 | } |
703 | ||
704 | sec = bfd_get_section_by_name (abfd, THUMB2ARM_GLUE_SECTION_NAME); | |
705 | ||
706 | if (sec == NULL) | |
707 | { | |
57e8b36a NC |
708 | flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY |
709 | | SEC_CODE | SEC_READONLY; | |
252b5132 RH |
710 | |
711 | sec = bfd_make_section (abfd, THUMB2ARM_GLUE_SECTION_NAME); | |
712 | ||
713 | if (sec == NULL | |
714 | || !bfd_set_section_flags (abfd, sec, flags) | |
715 | || !bfd_set_section_alignment (abfd, sec, 2)) | |
b34976b6 | 716 | return FALSE; |
9a5aca8c | 717 | |
57db232e | 718 | sec->gc_mark = 1; |
252b5132 RH |
719 | } |
720 | ||
b34976b6 | 721 | return TRUE; |
8afb0e02 NC |
722 | } |
723 | ||
724 | /* Select a BFD to be used to hold the sections used by the glue code. | |
725 | This function is called from the linker scripts in ld/emultempl/ | |
726 | {armelf/pe}.em */ | |
727 | ||
b34976b6 | 728 | bfd_boolean |
57e8b36a | 729 | bfd_elf32_arm_get_bfd_for_interworking (bfd *abfd, struct bfd_link_info *info) |
8afb0e02 NC |
730 | { |
731 | struct elf32_arm_link_hash_table *globals; | |
732 | ||
733 | /* If we are only performing a partial link | |
734 | do not bother getting a bfd to hold the glue. */ | |
1049f94e | 735 | if (info->relocatable) |
b34976b6 | 736 | return TRUE; |
8afb0e02 NC |
737 | |
738 | globals = elf32_arm_hash_table (info); | |
739 | ||
740 | BFD_ASSERT (globals != NULL); | |
741 | ||
742 | if (globals->bfd_of_glue_owner != NULL) | |
b34976b6 | 743 | return TRUE; |
8afb0e02 | 744 | |
252b5132 RH |
745 | /* Save the bfd for later use. */ |
746 | globals->bfd_of_glue_owner = abfd; | |
cedb70c5 | 747 | |
b34976b6 | 748 | return TRUE; |
252b5132 RH |
749 | } |
750 | ||
b34976b6 | 751 | bfd_boolean |
57e8b36a NC |
752 | bfd_elf32_arm_process_before_allocation (bfd *abfd, |
753 | struct bfd_link_info *link_info, | |
754 | int no_pipeline_knowledge, | |
755 | int byteswap_code) | |
252b5132 RH |
756 | { |
757 | Elf_Internal_Shdr *symtab_hdr; | |
6cdc0ccc | 758 | Elf_Internal_Rela *internal_relocs = NULL; |
252b5132 RH |
759 | Elf_Internal_Rela *irel, *irelend; |
760 | bfd_byte *contents = NULL; | |
252b5132 RH |
761 | |
762 | asection *sec; | |
763 | struct elf32_arm_link_hash_table *globals; | |
764 | ||
765 | /* If we are only performing a partial link do not bother | |
766 | to construct any glue. */ | |
1049f94e | 767 | if (link_info->relocatable) |
b34976b6 | 768 | return TRUE; |
252b5132 RH |
769 | |
770 | /* Here we have a bfd that is to be included on the link. We have a hook | |
771 | to do reloc rummaging, before section sizes are nailed down. */ | |
252b5132 RH |
772 | globals = elf32_arm_hash_table (link_info); |
773 | ||
774 | BFD_ASSERT (globals != NULL); | |
775 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); | |
776 | ||
ba96a88f | 777 | globals->no_pipeline_knowledge = no_pipeline_knowledge; |
e489d0ae PB |
778 | if (byteswap_code && !bfd_big_endian (abfd)) |
779 | { | |
d003868e AM |
780 | _bfd_error_handler (_("%B: BE8 images only valid in big-endian mode."), |
781 | abfd); | |
e489d0ae PB |
782 | return FALSE; |
783 | } | |
784 | globals->byteswap_code = byteswap_code; | |
f21f3fe0 | 785 | |
252b5132 RH |
786 | /* Rummage around all the relocs and map the glue vectors. */ |
787 | sec = abfd->sections; | |
788 | ||
789 | if (sec == NULL) | |
b34976b6 | 790 | return TRUE; |
252b5132 RH |
791 | |
792 | for (; sec != NULL; sec = sec->next) | |
793 | { | |
794 | if (sec->reloc_count == 0) | |
795 | continue; | |
796 | ||
797 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; | |
252b5132 | 798 | |
9b485d32 | 799 | /* Load the relocs. */ |
6cdc0ccc | 800 | internal_relocs |
57e8b36a | 801 | = _bfd_elf_link_read_relocs (abfd, sec, (void *) NULL, |
45d6a902 | 802 | (Elf_Internal_Rela *) NULL, FALSE); |
252b5132 | 803 | |
6cdc0ccc AM |
804 | if (internal_relocs == NULL) |
805 | goto error_return; | |
252b5132 | 806 | |
6cdc0ccc AM |
807 | irelend = internal_relocs + sec->reloc_count; |
808 | for (irel = internal_relocs; irel < irelend; irel++) | |
252b5132 RH |
809 | { |
810 | long r_type; | |
811 | unsigned long r_index; | |
252b5132 RH |
812 | |
813 | struct elf_link_hash_entry *h; | |
814 | ||
815 | r_type = ELF32_R_TYPE (irel->r_info); | |
816 | r_index = ELF32_R_SYM (irel->r_info); | |
817 | ||
9b485d32 | 818 | /* These are the only relocation types we care about. */ |
ba96a88f | 819 | if ( r_type != R_ARM_PC24 |
252b5132 RH |
820 | && r_type != R_ARM_THM_PC22) |
821 | continue; | |
822 | ||
823 | /* Get the section contents if we haven't done so already. */ | |
824 | if (contents == NULL) | |
825 | { | |
826 | /* Get cached copy if it exists. */ | |
827 | if (elf_section_data (sec)->this_hdr.contents != NULL) | |
828 | contents = elf_section_data (sec)->this_hdr.contents; | |
829 | else | |
830 | { | |
831 | /* Go get them off disk. */ | |
57e8b36a | 832 | if (! bfd_malloc_and_get_section (abfd, sec, &contents)) |
252b5132 RH |
833 | goto error_return; |
834 | } | |
835 | } | |
836 | ||
a7c10850 | 837 | /* If the relocation is not against a symbol it cannot concern us. */ |
252b5132 RH |
838 | h = NULL; |
839 | ||
9b485d32 | 840 | /* We don't care about local symbols. */ |
252b5132 RH |
841 | if (r_index < symtab_hdr->sh_info) |
842 | continue; | |
843 | ||
9b485d32 | 844 | /* This is an external symbol. */ |
252b5132 RH |
845 | r_index -= symtab_hdr->sh_info; |
846 | h = (struct elf_link_hash_entry *) | |
847 | elf_sym_hashes (abfd)[r_index]; | |
848 | ||
849 | /* If the relocation is against a static symbol it must be within | |
850 | the current section and so cannot be a cross ARM/Thumb relocation. */ | |
851 | if (h == NULL) | |
852 | continue; | |
853 | ||
854 | switch (r_type) | |
855 | { | |
856 | case R_ARM_PC24: | |
857 | /* This one is a call from arm code. We need to look up | |
2f0ca46a | 858 | the target of the call. If it is a thumb target, we |
252b5132 | 859 | insert glue. */ |
252b5132 RH |
860 | if (ELF_ST_TYPE(h->type) == STT_ARM_TFUNC) |
861 | record_arm_to_thumb_glue (link_info, h); | |
862 | break; | |
863 | ||
864 | case R_ARM_THM_PC22: | |
f21f3fe0 | 865 | /* This one is a call from thumb code. We look |
2f0ca46a | 866 | up the target of the call. If it is not a thumb |
bcbdc74c | 867 | target, we insert glue. */ |
252b5132 RH |
868 | if (ELF_ST_TYPE (h->type) != STT_ARM_TFUNC) |
869 | record_thumb_to_arm_glue (link_info, h); | |
870 | break; | |
871 | ||
872 | default: | |
873 | break; | |
874 | } | |
875 | } | |
6cdc0ccc AM |
876 | |
877 | if (contents != NULL | |
878 | && elf_section_data (sec)->this_hdr.contents != contents) | |
879 | free (contents); | |
880 | contents = NULL; | |
881 | ||
882 | if (internal_relocs != NULL | |
883 | && elf_section_data (sec)->relocs != internal_relocs) | |
884 | free (internal_relocs); | |
885 | internal_relocs = NULL; | |
252b5132 RH |
886 | } |
887 | ||
b34976b6 | 888 | return TRUE; |
9a5aca8c | 889 | |
252b5132 | 890 | error_return: |
6cdc0ccc AM |
891 | if (contents != NULL |
892 | && elf_section_data (sec)->this_hdr.contents != contents) | |
893 | free (contents); | |
894 | if (internal_relocs != NULL | |
895 | && elf_section_data (sec)->relocs != internal_relocs) | |
896 | free (internal_relocs); | |
9a5aca8c | 897 | |
b34976b6 | 898 | return FALSE; |
252b5132 | 899 | } |
7e392df6 | 900 | #endif |
252b5132 RH |
901 | |
902 | /* The thumb form of a long branch is a bit finicky, because the offset | |
903 | encoding is split over two fields, each in it's own instruction. They | |
f21f3fe0 | 904 | can occur in any order. So given a thumb form of long branch, and an |
252b5132 | 905 | offset, insert the offset into the thumb branch and return finished |
f21f3fe0 | 906 | instruction. |
252b5132 | 907 | |
f21f3fe0 | 908 | It takes two thumb instructions to encode the target address. Each has |
4cc11e76 | 909 | 11 bits to invest. The upper 11 bits are stored in one (identified by |
f21f3fe0 UD |
910 | H-0.. see below), the lower 11 bits are stored in the other (identified |
911 | by H-1). | |
252b5132 | 912 | |
f21f3fe0 | 913 | Combine together and shifted left by 1 (it's a half word address) and |
252b5132 RH |
914 | there you have it. |
915 | ||
916 | Op: 1111 = F, | |
917 | H-0, upper address-0 = 000 | |
918 | Op: 1111 = F, | |
919 | H-1, lower address-0 = 800 | |
920 | ||
f21f3fe0 | 921 | They can be ordered either way, but the arm tools I've seen always put |
252b5132 RH |
922 | the lower one first. It probably doesn't matter. [email protected] |
923 | ||
924 | XXX: Actually the order does matter. The second instruction (H-1) | |
925 | moves the computed address into the PC, so it must be the second one | |
926 | in the sequence. The problem, however is that whilst little endian code | |
927 | stores the instructions in HI then LOW order, big endian code does the | |
dfc5f959 | 928 | reverse. [email protected]. */ |
252b5132 | 929 | |
dfc5f959 NC |
930 | #define LOW_HI_ORDER 0xF800F000 |
931 | #define HI_LOW_ORDER 0xF000F800 | |
252b5132 RH |
932 | |
933 | static insn32 | |
57e8b36a | 934 | insert_thumb_branch (insn32 br_insn, int rel_off) |
252b5132 RH |
935 | { |
936 | unsigned int low_bits; | |
937 | unsigned int high_bits; | |
938 | ||
252b5132 RH |
939 | BFD_ASSERT ((rel_off & 1) != 1); |
940 | ||
dfc5f959 NC |
941 | rel_off >>= 1; /* Half word aligned address. */ |
942 | low_bits = rel_off & 0x000007FF; /* The bottom 11 bits. */ | |
943 | high_bits = (rel_off >> 11) & 0x000007FF; /* The top 11 bits. */ | |
252b5132 RH |
944 | |
945 | if ((br_insn & LOW_HI_ORDER) == LOW_HI_ORDER) | |
946 | br_insn = LOW_HI_ORDER | (low_bits << 16) | high_bits; | |
947 | else if ((br_insn & HI_LOW_ORDER) == HI_LOW_ORDER) | |
948 | br_insn = HI_LOW_ORDER | (high_bits << 16) | low_bits; | |
949 | else | |
9b485d32 | 950 | /* FIXME: abort is probably not the right call. [email protected] */ |
57e8b36a | 951 | abort (); /* Error - not a valid branch instruction form. */ |
252b5132 | 952 | |
252b5132 RH |
953 | return br_insn; |
954 | } | |
955 | ||
9b485d32 NC |
956 | /* Thumb code calling an ARM function. */ |
957 | ||
252b5132 | 958 | static int |
57e8b36a NC |
959 | elf32_thumb_to_arm_stub (struct bfd_link_info * info, |
960 | const char * name, | |
961 | bfd * input_bfd, | |
962 | bfd * output_bfd, | |
963 | asection * input_section, | |
964 | bfd_byte * hit_data, | |
965 | asection * sym_sec, | |
966 | bfd_vma offset, | |
967 | bfd_signed_vma addend, | |
968 | bfd_vma val) | |
252b5132 | 969 | { |
bcbdc74c | 970 | asection * s = 0; |
dc810e39 | 971 | bfd_vma my_offset; |
252b5132 RH |
972 | unsigned long int tmp; |
973 | long int ret_offset; | |
bcbdc74c NC |
974 | struct elf_link_hash_entry * myh; |
975 | struct elf32_arm_link_hash_table * globals; | |
252b5132 RH |
976 | |
977 | myh = find_thumb_glue (info, name, input_bfd); | |
978 | if (myh == NULL) | |
b34976b6 | 979 | return FALSE; |
252b5132 RH |
980 | |
981 | globals = elf32_arm_hash_table (info); | |
982 | ||
983 | BFD_ASSERT (globals != NULL); | |
984 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); | |
985 | ||
986 | my_offset = myh->root.u.def.value; | |
987 | ||
988 | s = bfd_get_section_by_name (globals->bfd_of_glue_owner, | |
989 | THUMB2ARM_GLUE_SECTION_NAME); | |
990 | ||
991 | BFD_ASSERT (s != NULL); | |
992 | BFD_ASSERT (s->contents != NULL); | |
993 | BFD_ASSERT (s->output_section != NULL); | |
994 | ||
995 | if ((my_offset & 0x01) == 0x01) | |
996 | { | |
997 | if (sym_sec != NULL | |
998 | && sym_sec->owner != NULL | |
999 | && !INTERWORK_FLAG (sym_sec->owner)) | |
1000 | { | |
8f615d07 | 1001 | (*_bfd_error_handler) |
d003868e AM |
1002 | (_("%B(%s): warning: interworking not enabled.\n" |
1003 | " first occurrence: %B: thumb call to arm"), | |
1004 | sym_sec->owner, input_bfd, name); | |
252b5132 | 1005 | |
b34976b6 | 1006 | return FALSE; |
252b5132 RH |
1007 | } |
1008 | ||
1009 | --my_offset; | |
1010 | myh->root.u.def.value = my_offset; | |
1011 | ||
dc810e39 | 1012 | bfd_put_16 (output_bfd, (bfd_vma) t2a1_bx_pc_insn, |
252b5132 RH |
1013 | s->contents + my_offset); |
1014 | ||
dc810e39 | 1015 | bfd_put_16 (output_bfd, (bfd_vma) t2a2_noop_insn, |
252b5132 RH |
1016 | s->contents + my_offset + 2); |
1017 | ||
1018 | ret_offset = | |
9b485d32 NC |
1019 | /* Address of destination of the stub. */ |
1020 | ((bfd_signed_vma) val) | |
252b5132 | 1021 | - ((bfd_signed_vma) |
57e8b36a NC |
1022 | /* Offset from the start of the current section |
1023 | to the start of the stubs. */ | |
9b485d32 NC |
1024 | (s->output_offset |
1025 | /* Offset of the start of this stub from the start of the stubs. */ | |
1026 | + my_offset | |
1027 | /* Address of the start of the current section. */ | |
1028 | + s->output_section->vma) | |
1029 | /* The branch instruction is 4 bytes into the stub. */ | |
1030 | + 4 | |
1031 | /* ARM branches work from the pc of the instruction + 8. */ | |
1032 | + 8); | |
252b5132 RH |
1033 | |
1034 | bfd_put_32 (output_bfd, | |
dc810e39 | 1035 | (bfd_vma) t2a3_b_insn | ((ret_offset >> 2) & 0x00FFFFFF), |
252b5132 RH |
1036 | s->contents + my_offset + 4); |
1037 | } | |
1038 | ||
1039 | BFD_ASSERT (my_offset <= globals->thumb_glue_size); | |
1040 | ||
427bfd90 NC |
1041 | /* Now go back and fix up the original BL insn to point to here. */ |
1042 | ret_offset = | |
1043 | /* Address of where the stub is located. */ | |
1044 | (s->output_section->vma + s->output_offset + my_offset) | |
1045 | /* Address of where the BL is located. */ | |
57e8b36a NC |
1046 | - (input_section->output_section->vma + input_section->output_offset |
1047 | + offset) | |
427bfd90 NC |
1048 | /* Addend in the relocation. */ |
1049 | - addend | |
1050 | /* Biassing for PC-relative addressing. */ | |
1051 | - 8; | |
252b5132 RH |
1052 | |
1053 | tmp = bfd_get_32 (input_bfd, hit_data | |
1054 | - input_section->vma); | |
1055 | ||
1056 | bfd_put_32 (output_bfd, | |
dc810e39 | 1057 | (bfd_vma) insert_thumb_branch (tmp, ret_offset), |
252b5132 RH |
1058 | hit_data - input_section->vma); |
1059 | ||
b34976b6 | 1060 | return TRUE; |
252b5132 RH |
1061 | } |
1062 | ||
9b485d32 NC |
1063 | /* Arm code calling a Thumb function. */ |
1064 | ||
252b5132 | 1065 | static int |
57e8b36a NC |
1066 | elf32_arm_to_thumb_stub (struct bfd_link_info * info, |
1067 | const char * name, | |
1068 | bfd * input_bfd, | |
1069 | bfd * output_bfd, | |
1070 | asection * input_section, | |
1071 | bfd_byte * hit_data, | |
1072 | asection * sym_sec, | |
1073 | bfd_vma offset, | |
1074 | bfd_signed_vma addend, | |
1075 | bfd_vma val) | |
252b5132 RH |
1076 | { |
1077 | unsigned long int tmp; | |
dc810e39 | 1078 | bfd_vma my_offset; |
bcbdc74c | 1079 | asection * s; |
252b5132 | 1080 | long int ret_offset; |
bcbdc74c NC |
1081 | struct elf_link_hash_entry * myh; |
1082 | struct elf32_arm_link_hash_table * globals; | |
252b5132 RH |
1083 | |
1084 | myh = find_arm_glue (info, name, input_bfd); | |
1085 | if (myh == NULL) | |
b34976b6 | 1086 | return FALSE; |
252b5132 RH |
1087 | |
1088 | globals = elf32_arm_hash_table (info); | |
1089 | ||
1090 | BFD_ASSERT (globals != NULL); | |
1091 | BFD_ASSERT (globals->bfd_of_glue_owner != NULL); | |
1092 | ||
1093 | my_offset = myh->root.u.def.value; | |
1094 | s = bfd_get_section_by_name (globals->bfd_of_glue_owner, | |
1095 | ARM2THUMB_GLUE_SECTION_NAME); | |
1096 | BFD_ASSERT (s != NULL); | |
1097 | BFD_ASSERT (s->contents != NULL); | |
1098 | BFD_ASSERT (s->output_section != NULL); | |
1099 | ||
1100 | if ((my_offset & 0x01) == 0x01) | |
1101 | { | |
1102 | if (sym_sec != NULL | |
1103 | && sym_sec->owner != NULL | |
1104 | && !INTERWORK_FLAG (sym_sec->owner)) | |
1105 | { | |
8f615d07 | 1106 | (*_bfd_error_handler) |
d003868e AM |
1107 | (_("%B(%s): warning: interworking not enabled.\n" |
1108 | " first occurrence: %B: arm call to thumb"), | |
1109 | sym_sec->owner, input_bfd, name); | |
252b5132 | 1110 | } |
9b485d32 | 1111 | |
252b5132 RH |
1112 | --my_offset; |
1113 | myh->root.u.def.value = my_offset; | |
1114 | ||
dc810e39 | 1115 | bfd_put_32 (output_bfd, (bfd_vma) a2t1_ldr_insn, |
252b5132 RH |
1116 | s->contents + my_offset); |
1117 | ||
dc810e39 | 1118 | bfd_put_32 (output_bfd, (bfd_vma) a2t2_bx_r12_insn, |
252b5132 RH |
1119 | s->contents + my_offset + 4); |
1120 | ||
1121 | /* It's a thumb address. Add the low order bit. */ | |
1122 | bfd_put_32 (output_bfd, val | a2t3_func_addr_insn, | |
1123 | s->contents + my_offset + 8); | |
1124 | } | |
1125 | ||
1126 | BFD_ASSERT (my_offset <= globals->arm_glue_size); | |
1127 | ||
1128 | tmp = bfd_get_32 (input_bfd, hit_data); | |
1129 | tmp = tmp & 0xFF000000; | |
1130 | ||
9b485d32 | 1131 | /* Somehow these are both 4 too far, so subtract 8. */ |
dc810e39 AM |
1132 | ret_offset = (s->output_offset |
1133 | + my_offset | |
1134 | + s->output_section->vma | |
1135 | - (input_section->output_offset | |
1136 | + input_section->output_section->vma | |
1137 | + offset + addend) | |
1138 | - 8); | |
9a5aca8c | 1139 | |
252b5132 RH |
1140 | tmp = tmp | ((ret_offset >> 2) & 0x00FFFFFF); |
1141 | ||
dc810e39 | 1142 | bfd_put_32 (output_bfd, (bfd_vma) tmp, hit_data - input_section->vma); |
252b5132 | 1143 | |
b34976b6 | 1144 | return TRUE; |
252b5132 RH |
1145 | } |
1146 | ||
1147 | /* Perform a relocation as part of a final link. */ | |
9b485d32 | 1148 | |
252b5132 | 1149 | static bfd_reloc_status_type |
57e8b36a NC |
1150 | elf32_arm_final_link_relocate (reloc_howto_type * howto, |
1151 | bfd * input_bfd, | |
1152 | bfd * output_bfd, | |
1153 | asection * input_section, | |
1154 | bfd_byte * contents, | |
1155 | Elf_Internal_Rela * rel, | |
1156 | bfd_vma value, | |
1157 | struct bfd_link_info * info, | |
1158 | asection * sym_sec, | |
1159 | const char * sym_name, | |
1160 | int sym_flags, | |
1161 | struct elf_link_hash_entry * h) | |
252b5132 RH |
1162 | { |
1163 | unsigned long r_type = howto->type; | |
1164 | unsigned long r_symndx; | |
1165 | bfd_byte * hit_data = contents + rel->r_offset; | |
1166 | bfd * dynobj = NULL; | |
1167 | Elf_Internal_Shdr * symtab_hdr; | |
1168 | struct elf_link_hash_entry ** sym_hashes; | |
1169 | bfd_vma * local_got_offsets; | |
1170 | asection * sgot = NULL; | |
1171 | asection * splt = NULL; | |
1172 | asection * sreloc = NULL; | |
252b5132 | 1173 | bfd_vma addend; |
ba96a88f NC |
1174 | bfd_signed_vma signed_addend; |
1175 | struct elf32_arm_link_hash_table * globals; | |
f21f3fe0 | 1176 | |
cac15327 NC |
1177 | /* If the start address has been set, then set the EF_ARM_HASENTRY |
1178 | flag. Setting this more than once is redundant, but the cost is | |
1179 | not too high, and it keeps the code simple. | |
99e4ae17 | 1180 | |
cac15327 NC |
1181 | The test is done here, rather than somewhere else, because the |
1182 | start address is only set just before the final link commences. | |
1183 | ||
1184 | Note - if the user deliberately sets a start address of 0, the | |
1185 | flag will not be set. */ | |
1186 | if (bfd_get_start_address (output_bfd) != 0) | |
1187 | elf_elfheader (output_bfd)->e_flags |= EF_ARM_HASENTRY; | |
99e4ae17 | 1188 | |
ba96a88f | 1189 | globals = elf32_arm_hash_table (info); |
f21f3fe0 | 1190 | |
252b5132 RH |
1191 | dynobj = elf_hash_table (info)->dynobj; |
1192 | if (dynobj) | |
1193 | { | |
1194 | sgot = bfd_get_section_by_name (dynobj, ".got"); | |
1195 | splt = bfd_get_section_by_name (dynobj, ".plt"); | |
1196 | } | |
1197 | symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr; | |
1198 | sym_hashes = elf_sym_hashes (input_bfd); | |
1199 | local_got_offsets = elf_local_got_offsets (input_bfd); | |
1200 | r_symndx = ELF32_R_SYM (rel->r_info); | |
1201 | ||
acf8aed4 | 1202 | #if USE_REL |
ba96a88f NC |
1203 | addend = bfd_get_32 (input_bfd, hit_data) & howto->src_mask; |
1204 | ||
1205 | if (addend & ((howto->src_mask + 1) >> 1)) | |
1206 | { | |
1207 | signed_addend = -1; | |
1208 | signed_addend &= ~ howto->src_mask; | |
1209 | signed_addend |= addend; | |
1210 | } | |
1211 | else | |
1212 | signed_addend = addend; | |
252b5132 | 1213 | #else |
ba96a88f | 1214 | addend = signed_addend = rel->r_addend; |
252b5132 | 1215 | #endif |
f21f3fe0 | 1216 | |
252b5132 RH |
1217 | switch (r_type) |
1218 | { | |
1219 | case R_ARM_NONE: | |
1220 | return bfd_reloc_ok; | |
1221 | ||
1222 | case R_ARM_PC24: | |
1223 | case R_ARM_ABS32: | |
1224 | case R_ARM_REL32: | |
dfc5f959 NC |
1225 | #ifndef OLD_ARM_ABI |
1226 | case R_ARM_XPC25: | |
1227 | #endif | |
7359ea65 | 1228 | case R_ARM_PLT32: |
5e681ec4 PB |
1229 | /* r_symndx will be zero only for relocs against symbols |
1230 | from removed linkonce sections, or sections discarded by | |
1231 | a linker script. */ | |
1232 | if (r_symndx == 0) | |
1233 | return bfd_reloc_ok; | |
1234 | ||
7359ea65 DJ |
1235 | /* Handle relocations which should use the PLT entry. ABS32/REL32 |
1236 | will use the symbol's value, which may point to a PLT entry, but we | |
1237 | don't need to handle that here. If we created a PLT entry, all | |
1238 | branches in this object should go to it. */ | |
1239 | if ((r_type != R_ARM_ABS32 && r_type != R_ARM_REL32) | |
1240 | && h != NULL | |
c84cd8ee | 1241 | && splt != NULL |
7359ea65 DJ |
1242 | && h->plt.offset != (bfd_vma) -1) |
1243 | { | |
c84cd8ee DJ |
1244 | /* If we've created a .plt section, and assigned a PLT entry to |
1245 | this function, it should not be known to bind locally. If | |
1246 | it were, we would have cleared the PLT entry. */ | |
7359ea65 DJ |
1247 | BFD_ASSERT (!SYMBOL_CALLS_LOCAL (info, h)); |
1248 | ||
1249 | value = (splt->output_section->vma | |
1250 | + splt->output_offset | |
1251 | + h->plt.offset); | |
1252 | return _bfd_final_link_relocate (howto, input_bfd, input_section, | |
1253 | contents, rel->r_offset, value, | |
1254 | (bfd_vma) 0); | |
1255 | } | |
1256 | ||
252b5132 | 1257 | /* When generating a shared object, these relocations are copied |
9b485d32 | 1258 | into the output file to be resolved at run time. */ |
7359ea65 DJ |
1259 | if (info->shared |
1260 | && (input_section->flags & SEC_ALLOC) | |
955af222 PB |
1261 | && (r_type != R_ARM_REL32 |
1262 | || !SYMBOL_CALLS_LOCAL (info, h)) | |
7359ea65 DJ |
1263 | && (h == NULL |
1264 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
1265 | || h->root.type != bfd_link_hash_undefweak) | |
1266 | && r_type != R_ARM_PC24 | |
1267 | && r_type != R_ARM_PLT32) | |
252b5132 | 1268 | { |
947216bf AM |
1269 | Elf_Internal_Rela outrel; |
1270 | bfd_byte *loc; | |
b34976b6 | 1271 | bfd_boolean skip, relocate; |
f21f3fe0 | 1272 | |
252b5132 RH |
1273 | if (sreloc == NULL) |
1274 | { | |
1275 | const char * name; | |
f21f3fe0 | 1276 | |
252b5132 RH |
1277 | name = (bfd_elf_string_from_elf_section |
1278 | (input_bfd, | |
1279 | elf_elfheader (input_bfd)->e_shstrndx, | |
1280 | elf_section_data (input_section)->rel_hdr.sh_name)); | |
1281 | if (name == NULL) | |
1282 | return bfd_reloc_notsupported; | |
f21f3fe0 | 1283 | |
252b5132 RH |
1284 | BFD_ASSERT (strncmp (name, ".rel", 4) == 0 |
1285 | && strcmp (bfd_get_section_name (input_bfd, | |
1286 | input_section), | |
1287 | name + 4) == 0); | |
f21f3fe0 | 1288 | |
252b5132 RH |
1289 | sreloc = bfd_get_section_by_name (dynobj, name); |
1290 | BFD_ASSERT (sreloc != NULL); | |
1291 | } | |
f21f3fe0 | 1292 | |
b34976b6 AM |
1293 | skip = FALSE; |
1294 | relocate = FALSE; | |
f21f3fe0 | 1295 | |
c629eae0 JJ |
1296 | outrel.r_offset = |
1297 | _bfd_elf_section_offset (output_bfd, info, input_section, | |
1298 | rel->r_offset); | |
1299 | if (outrel.r_offset == (bfd_vma) -1) | |
b34976b6 | 1300 | skip = TRUE; |
0bb2d96a | 1301 | else if (outrel.r_offset == (bfd_vma) -2) |
b34976b6 | 1302 | skip = TRUE, relocate = TRUE; |
252b5132 RH |
1303 | outrel.r_offset += (input_section->output_section->vma |
1304 | + input_section->output_offset); | |
f21f3fe0 | 1305 | |
252b5132 | 1306 | if (skip) |
0bb2d96a | 1307 | memset (&outrel, 0, sizeof outrel); |
5e681ec4 PB |
1308 | else if (h != NULL |
1309 | && h->dynindx != -1 | |
7359ea65 | 1310 | && (!info->shared |
5e681ec4 PB |
1311 | || !info->symbolic |
1312 | || (h->elf_link_hash_flags | |
1313 | & ELF_LINK_HASH_DEF_REGULAR) == 0)) | |
1314 | outrel.r_info = ELF32_R_INFO (h->dynindx, r_type); | |
252b5132 RH |
1315 | else |
1316 | { | |
5e681ec4 PB |
1317 | /* This symbol is local, or marked to become local. */ |
1318 | relocate = TRUE; | |
1319 | outrel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE); | |
252b5132 | 1320 | } |
f21f3fe0 | 1321 | |
947216bf AM |
1322 | loc = sreloc->contents; |
1323 | loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rel); | |
1324 | bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc); | |
9a5aca8c | 1325 | |
f21f3fe0 | 1326 | /* If this reloc is against an external symbol, we do not want to |
252b5132 | 1327 | fiddle with the addend. Otherwise, we need to include the symbol |
9b485d32 | 1328 | value so that it becomes an addend for the dynamic reloc. */ |
252b5132 RH |
1329 | if (! relocate) |
1330 | return bfd_reloc_ok; | |
9a5aca8c | 1331 | |
f21f3fe0 | 1332 | return _bfd_final_link_relocate (howto, input_bfd, input_section, |
252b5132 RH |
1333 | contents, rel->r_offset, value, |
1334 | (bfd_vma) 0); | |
1335 | } | |
1336 | else switch (r_type) | |
1337 | { | |
dfc5f959 NC |
1338 | #ifndef OLD_ARM_ABI |
1339 | case R_ARM_XPC25: /* Arm BLX instruction. */ | |
1340 | #endif | |
1341 | case R_ARM_PC24: /* Arm B/BL instruction */ | |
7359ea65 | 1342 | case R_ARM_PLT32: |
dfc5f959 NC |
1343 | #ifndef OLD_ARM_ABI |
1344 | if (r_type == R_ARM_XPC25) | |
252b5132 | 1345 | { |
dfc5f959 NC |
1346 | /* Check for Arm calling Arm function. */ |
1347 | /* FIXME: Should we translate the instruction into a BL | |
1348 | instruction instead ? */ | |
1349 | if (sym_flags != STT_ARM_TFUNC) | |
d003868e AM |
1350 | (*_bfd_error_handler) |
1351 | (_("\%B: Warning: Arm BLX instruction targets Arm function '%s'."), | |
1352 | input_bfd, | |
1353 | h ? h->root.root.string : "(local)"); | |
dfc5f959 NC |
1354 | } |
1355 | else | |
1356 | #endif | |
1357 | { | |
1358 | /* Check for Arm calling Thumb function. */ | |
1359 | if (sym_flags == STT_ARM_TFUNC) | |
1360 | { | |
57e8b36a NC |
1361 | elf32_arm_to_thumb_stub (info, sym_name, input_bfd, |
1362 | output_bfd, input_section, | |
1363 | hit_data, sym_sec, rel->r_offset, | |
dfc5f959 NC |
1364 | signed_addend, value); |
1365 | return bfd_reloc_ok; | |
1366 | } | |
252b5132 | 1367 | } |
ba96a88f NC |
1368 | |
1369 | if ( strcmp (bfd_get_target (input_bfd), "elf32-littlearm-oabi") == 0 | |
1370 | || strcmp (bfd_get_target (input_bfd), "elf32-bigarm-oabi") == 0) | |
1371 | { | |
1372 | /* The old way of doing things. Trearing the addend as a | |
1373 | byte sized field and adding in the pipeline offset. */ | |
ba96a88f NC |
1374 | value -= (input_section->output_section->vma |
1375 | + input_section->output_offset); | |
1376 | value -= rel->r_offset; | |
1377 | value += addend; | |
f21f3fe0 | 1378 | |
ba96a88f NC |
1379 | if (! globals->no_pipeline_knowledge) |
1380 | value -= 8; | |
1381 | } | |
1382 | else | |
1383 | { | |
1384 | /* The ARM ELF ABI says that this reloc is computed as: S - P + A | |
1385 | where: | |
1386 | S is the address of the symbol in the relocation. | |
1387 | P is address of the instruction being relocated. | |
1388 | A is the addend (extracted from the instruction) in bytes. | |
f21f3fe0 | 1389 | |
ba96a88f | 1390 | S is held in 'value'. |
57e8b36a NC |
1391 | P is the base address of the section containing the |
1392 | instruction plus the offset of the reloc into that | |
1393 | section, ie: | |
ba96a88f NC |
1394 | (input_section->output_section->vma + |
1395 | input_section->output_offset + | |
1396 | rel->r_offset). | |
1397 | A is the addend, converted into bytes, ie: | |
1398 | (signed_addend * 4) | |
1399 | ||
1400 | Note: None of these operations have knowledge of the pipeline | |
57e8b36a NC |
1401 | size of the processor, thus it is up to the assembler to |
1402 | encode this information into the addend. */ | |
ba96a88f NC |
1403 | value -= (input_section->output_section->vma |
1404 | + input_section->output_offset); | |
1405 | value -= rel->r_offset; | |
1406 | value += (signed_addend << howto->size); | |
f21f3fe0 | 1407 | |
57e8b36a NC |
1408 | /* Previous versions of this code also used to add in the |
1409 | pipeline offset here. This is wrong because the linker is | |
1410 | not supposed to know about such things, and one day it might | |
1411 | change. In order to support old binaries that need the old | |
1412 | behaviour however, so we attempt to detect which ABI was | |
1413 | used to create the reloc. */ | |
ba96a88f | 1414 | if (! globals->no_pipeline_knowledge) |
f21f3fe0 | 1415 | { |
ba96a88f | 1416 | Elf_Internal_Ehdr * i_ehdrp; /* Elf file header, internal form */ |
f21f3fe0 | 1417 | |
ba96a88f | 1418 | i_ehdrp = elf_elfheader (input_bfd); |
f21f3fe0 | 1419 | |
ba96a88f NC |
1420 | if (i_ehdrp->e_ident[EI_OSABI] == 0) |
1421 | value -= 8; | |
1422 | } | |
1423 | } | |
23080146 | 1424 | |
dcb5e6e6 NC |
1425 | signed_addend = value; |
1426 | signed_addend >>= howto->rightshift; | |
9a5aca8c | 1427 | |
59f2c4e7 NC |
1428 | /* It is not an error for an undefined weak reference to be |
1429 | out of range. Any program that branches to such a symbol | |
9a5aca8c AM |
1430 | is going to crash anyway, so there is no point worrying |
1431 | about getting the destination exactly right. */ | |
59f2c4e7 NC |
1432 | if (! h || h->root.type != bfd_link_hash_undefweak) |
1433 | { | |
9b485d32 | 1434 | /* Perform a signed range check. */ |
dcb5e6e6 | 1435 | if ( signed_addend > ((bfd_signed_vma) (howto->dst_mask >> 1)) |
59f2c4e7 NC |
1436 | || signed_addend < - ((bfd_signed_vma) ((howto->dst_mask + 1) >> 1))) |
1437 | return bfd_reloc_overflow; | |
1438 | } | |
9a5aca8c | 1439 | |
dcb5e6e6 NC |
1440 | #ifndef OLD_ARM_ABI |
1441 | /* If necessary set the H bit in the BLX instruction. */ | |
1442 | if (r_type == R_ARM_XPC25 && ((value & 2) == 2)) | |
1443 | value = (signed_addend & howto->dst_mask) | |
1444 | | (bfd_get_32 (input_bfd, hit_data) & (~ howto->dst_mask)) | |
1445 | | (1 << 24); | |
1446 | else | |
1447 | #endif | |
1448 | value = (signed_addend & howto->dst_mask) | |
1449 | | (bfd_get_32 (input_bfd, hit_data) & (~ howto->dst_mask)); | |
252b5132 | 1450 | break; |
f21f3fe0 | 1451 | |
252b5132 RH |
1452 | case R_ARM_ABS32: |
1453 | value += addend; | |
1454 | if (sym_flags == STT_ARM_TFUNC) | |
1455 | value |= 1; | |
1456 | break; | |
f21f3fe0 | 1457 | |
252b5132 RH |
1458 | case R_ARM_REL32: |
1459 | value -= (input_section->output_section->vma | |
62efb346 | 1460 | + input_section->output_offset + rel->r_offset); |
252b5132 RH |
1461 | value += addend; |
1462 | break; | |
1463 | } | |
f21f3fe0 | 1464 | |
252b5132 RH |
1465 | bfd_put_32 (input_bfd, value, hit_data); |
1466 | return bfd_reloc_ok; | |
1467 | ||
1468 | case R_ARM_ABS8: | |
1469 | value += addend; | |
1470 | if ((long) value > 0x7f || (long) value < -0x80) | |
1471 | return bfd_reloc_overflow; | |
1472 | ||
1473 | bfd_put_8 (input_bfd, value, hit_data); | |
1474 | return bfd_reloc_ok; | |
1475 | ||
1476 | case R_ARM_ABS16: | |
1477 | value += addend; | |
1478 | ||
1479 | if ((long) value > 0x7fff || (long) value < -0x8000) | |
1480 | return bfd_reloc_overflow; | |
1481 | ||
1482 | bfd_put_16 (input_bfd, value, hit_data); | |
1483 | return bfd_reloc_ok; | |
1484 | ||
1485 | case R_ARM_ABS12: | |
1486 | /* Support ldr and str instruction for the arm */ | |
1487 | /* Also thumb b (unconditional branch). ??? Really? */ | |
1488 | value += addend; | |
1489 | ||
1490 | if ((long) value > 0x7ff || (long) value < -0x800) | |
1491 | return bfd_reloc_overflow; | |
1492 | ||
1493 | value |= (bfd_get_32 (input_bfd, hit_data) & 0xfffff000); | |
1494 | bfd_put_32 (input_bfd, value, hit_data); | |
1495 | return bfd_reloc_ok; | |
1496 | ||
1497 | case R_ARM_THM_ABS5: | |
9b485d32 | 1498 | /* Support ldr and str instructions for the thumb. */ |
acf8aed4 | 1499 | #if USE_REL |
252b5132 RH |
1500 | /* Need to refetch addend. */ |
1501 | addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask; | |
1502 | /* ??? Need to determine shift amount from operand size. */ | |
1503 | addend >>= howto->rightshift; | |
1504 | #endif | |
1505 | value += addend; | |
1506 | ||
1507 | /* ??? Isn't value unsigned? */ | |
1508 | if ((long) value > 0x1f || (long) value < -0x10) | |
1509 | return bfd_reloc_overflow; | |
1510 | ||
1511 | /* ??? Value needs to be properly shifted into place first. */ | |
1512 | value |= bfd_get_16 (input_bfd, hit_data) & 0xf83f; | |
1513 | bfd_put_16 (input_bfd, value, hit_data); | |
1514 | return bfd_reloc_ok; | |
1515 | ||
dfc5f959 NC |
1516 | #ifndef OLD_ARM_ABI |
1517 | case R_ARM_THM_XPC22: | |
1518 | #endif | |
252b5132 | 1519 | case R_ARM_THM_PC22: |
dfc5f959 | 1520 | /* Thumb BL (branch long instruction). */ |
252b5132 | 1521 | { |
b34976b6 AM |
1522 | bfd_vma relocation; |
1523 | bfd_boolean overflow = FALSE; | |
1524 | bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data); | |
1525 | bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2); | |
df212a7e | 1526 | bfd_signed_vma reloc_signed_max = ((1 << (howto->bitsize - 1)) - 1) >> howto->rightshift; |
ba96a88f | 1527 | bfd_signed_vma reloc_signed_min = ~ reloc_signed_max; |
b34976b6 | 1528 | bfd_vma check; |
252b5132 | 1529 | bfd_signed_vma signed_check; |
252b5132 | 1530 | |
acf8aed4 | 1531 | #if USE_REL |
252b5132 RH |
1532 | /* Need to refetch the addend and squish the two 11 bit pieces |
1533 | together. */ | |
1534 | { | |
ba96a88f NC |
1535 | bfd_vma upper = upper_insn & 0x7ff; |
1536 | bfd_vma lower = lower_insn & 0x7ff; | |
9b485d32 | 1537 | upper = (upper ^ 0x400) - 0x400; /* Sign extend. */ |
252b5132 | 1538 | addend = (upper << 12) | (lower << 1); |
ba96a88f | 1539 | signed_addend = addend; |
252b5132 RH |
1540 | } |
1541 | #endif | |
dfc5f959 NC |
1542 | #ifndef OLD_ARM_ABI |
1543 | if (r_type == R_ARM_THM_XPC22) | |
1544 | { | |
1545 | /* Check for Thumb to Thumb call. */ | |
1546 | /* FIXME: Should we translate the instruction into a BL | |
1547 | instruction instead ? */ | |
1548 | if (sym_flags == STT_ARM_TFUNC) | |
d003868e AM |
1549 | (*_bfd_error_handler) |
1550 | (_("%B: Warning: Thumb BLX instruction targets thumb function '%s'."), | |
1551 | input_bfd, | |
1552 | h ? h->root.root.string : "(local)"); | |
dfc5f959 NC |
1553 | } |
1554 | else | |
1555 | #endif | |
252b5132 | 1556 | { |
dfc5f959 NC |
1557 | /* If it is not a call to Thumb, assume call to Arm. |
1558 | If it is a call relative to a section name, then it is not a | |
1559 | function call at all, but rather a long jump. */ | |
1560 | if (sym_flags != STT_ARM_TFUNC && sym_flags != STT_SECTION) | |
1561 | { | |
1562 | if (elf32_thumb_to_arm_stub | |
1563 | (info, sym_name, input_bfd, output_bfd, input_section, | |
1564 | hit_data, sym_sec, rel->r_offset, signed_addend, value)) | |
1565 | return bfd_reloc_ok; | |
1566 | else | |
1567 | return bfd_reloc_dangerous; | |
1568 | } | |
252b5132 | 1569 | } |
f21f3fe0 | 1570 | |
ba96a88f | 1571 | relocation = value + signed_addend; |
f21f3fe0 | 1572 | |
252b5132 | 1573 | relocation -= (input_section->output_section->vma |
ba96a88f NC |
1574 | + input_section->output_offset |
1575 | + rel->r_offset); | |
9a5aca8c | 1576 | |
ba96a88f NC |
1577 | if (! globals->no_pipeline_knowledge) |
1578 | { | |
9b485d32 | 1579 | Elf_Internal_Ehdr * i_ehdrp; /* Elf file header, internal form. */ |
9a5aca8c | 1580 | |
ba96a88f | 1581 | i_ehdrp = elf_elfheader (input_bfd); |
f21f3fe0 | 1582 | |
ba96a88f NC |
1583 | /* Previous versions of this code also used to add in the pipline |
1584 | offset here. This is wrong because the linker is not supposed | |
1585 | to know about such things, and one day it might change. In order | |
1586 | to support old binaries that need the old behaviour however, so | |
1587 | we attempt to detect which ABI was used to create the reloc. */ | |
1588 | if ( strcmp (bfd_get_target (input_bfd), "elf32-littlearm-oabi") == 0 | |
1589 | || strcmp (bfd_get_target (input_bfd), "elf32-bigarm-oabi") == 0 | |
1590 | || i_ehdrp->e_ident[EI_OSABI] == 0) | |
1591 | relocation += 4; | |
1592 | } | |
f21f3fe0 | 1593 | |
252b5132 RH |
1594 | check = relocation >> howto->rightshift; |
1595 | ||
1596 | /* If this is a signed value, the rightshift just dropped | |
1597 | leading 1 bits (assuming twos complement). */ | |
1598 | if ((bfd_signed_vma) relocation >= 0) | |
1599 | signed_check = check; | |
1600 | else | |
1601 | signed_check = check | ~((bfd_vma) -1 >> howto->rightshift); | |
1602 | ||
252b5132 | 1603 | /* Assumes two's complement. */ |
ba96a88f | 1604 | if (signed_check > reloc_signed_max || signed_check < reloc_signed_min) |
b34976b6 | 1605 | overflow = TRUE; |
252b5132 | 1606 | |
df425bc0 | 1607 | #ifndef OLD_ARM_ABI |
4f3c3dbb NC |
1608 | if (r_type == R_ARM_THM_XPC22 |
1609 | && ((lower_insn & 0x1800) == 0x0800)) | |
c62e1cc3 NC |
1610 | /* For a BLX instruction, make sure that the relocation is rounded up |
1611 | to a word boundary. This follows the semantics of the instruction | |
1612 | which specifies that bit 1 of the target address will come from bit | |
1613 | 1 of the base address. */ | |
1614 | relocation = (relocation + 2) & ~ 3; | |
99e4ae17 | 1615 | #endif |
c62e1cc3 NC |
1616 | /* Put RELOCATION back into the insn. */ |
1617 | upper_insn = (upper_insn & ~(bfd_vma) 0x7ff) | ((relocation >> 12) & 0x7ff); | |
1618 | lower_insn = (lower_insn & ~(bfd_vma) 0x7ff) | ((relocation >> 1) & 0x7ff); | |
1619 | ||
252b5132 RH |
1620 | /* Put the relocated value back in the object file: */ |
1621 | bfd_put_16 (input_bfd, upper_insn, hit_data); | |
1622 | bfd_put_16 (input_bfd, lower_insn, hit_data + 2); | |
1623 | ||
1624 | return (overflow ? bfd_reloc_overflow : bfd_reloc_ok); | |
1625 | } | |
1626 | break; | |
1627 | ||
51c5503b NC |
1628 | case R_ARM_THM_PC11: |
1629 | /* Thumb B (branch) instruction). */ | |
1630 | { | |
6cf9e9fe | 1631 | bfd_signed_vma relocation; |
51c5503b NC |
1632 | bfd_signed_vma reloc_signed_max = (1 << (howto->bitsize - 1)) - 1; |
1633 | bfd_signed_vma reloc_signed_min = ~ reloc_signed_max; | |
51c5503b NC |
1634 | bfd_signed_vma signed_check; |
1635 | ||
acf8aed4 | 1636 | #if USE_REL |
51c5503b NC |
1637 | /* Need to refetch addend. */ |
1638 | addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask; | |
6cf9e9fe NC |
1639 | if (addend & ((howto->src_mask + 1) >> 1)) |
1640 | { | |
1641 | signed_addend = -1; | |
1642 | signed_addend &= ~ howto->src_mask; | |
1643 | signed_addend |= addend; | |
1644 | } | |
1645 | else | |
1646 | signed_addend = addend; | |
1647 | /* The value in the insn has been right shifted. We need to | |
1648 | undo this, so that we can perform the address calculation | |
1649 | in terms of bytes. */ | |
1650 | signed_addend <<= howto->rightshift; | |
51c5503b | 1651 | #endif |
6cf9e9fe | 1652 | relocation = value + signed_addend; |
51c5503b NC |
1653 | |
1654 | relocation -= (input_section->output_section->vma | |
1655 | + input_section->output_offset | |
1656 | + rel->r_offset); | |
1657 | ||
6cf9e9fe NC |
1658 | relocation >>= howto->rightshift; |
1659 | signed_check = relocation; | |
1660 | relocation &= howto->dst_mask; | |
51c5503b | 1661 | relocation |= (bfd_get_16 (input_bfd, hit_data) & (~ howto->dst_mask)); |
cedb70c5 | 1662 | |
51c5503b NC |
1663 | bfd_put_16 (input_bfd, relocation, hit_data); |
1664 | ||
1665 | /* Assumes two's complement. */ | |
1666 | if (signed_check > reloc_signed_max || signed_check < reloc_signed_min) | |
1667 | return bfd_reloc_overflow; | |
1668 | ||
1669 | return bfd_reloc_ok; | |
1670 | } | |
cedb70c5 | 1671 | |
1f433d93 | 1672 | #ifndef OLD_ARM_ABI |
8375c36b PB |
1673 | case R_ARM_ALU_PCREL7_0: |
1674 | case R_ARM_ALU_PCREL15_8: | |
1675 | case R_ARM_ALU_PCREL23_15: | |
1676 | { | |
1677 | bfd_vma insn; | |
1678 | bfd_vma relocation; | |
1679 | ||
1680 | insn = bfd_get_32 (input_bfd, hit_data); | |
1681 | #if USE_REL | |
1682 | /* Extract the addend. */ | |
1683 | addend = (insn & 0xff) << ((insn & 0xf00) >> 7); | |
1684 | signed_addend = addend; | |
1685 | #endif | |
1686 | relocation = value + signed_addend; | |
1687 | ||
1688 | relocation -= (input_section->output_section->vma | |
1689 | + input_section->output_offset | |
1690 | + rel->r_offset); | |
1691 | insn = (insn & ~0xfff) | |
1692 | | ((howto->bitpos << 7) & 0xf00) | |
1693 | | ((relocation >> howto->bitpos) & 0xff); | |
1694 | bfd_put_32 (input_bfd, value, hit_data); | |
1695 | } | |
1696 | return bfd_reloc_ok; | |
1f433d93 | 1697 | #endif |
8375c36b | 1698 | |
252b5132 RH |
1699 | case R_ARM_GNU_VTINHERIT: |
1700 | case R_ARM_GNU_VTENTRY: | |
1701 | return bfd_reloc_ok; | |
1702 | ||
1703 | case R_ARM_COPY: | |
1704 | return bfd_reloc_notsupported; | |
1705 | ||
1706 | case R_ARM_GLOB_DAT: | |
1707 | return bfd_reloc_notsupported; | |
1708 | ||
1709 | case R_ARM_JUMP_SLOT: | |
1710 | return bfd_reloc_notsupported; | |
1711 | ||
1712 | case R_ARM_RELATIVE: | |
1713 | return bfd_reloc_notsupported; | |
1714 | ||
1715 | case R_ARM_GOTOFF: | |
1716 | /* Relocation is relative to the start of the | |
1717 | global offset table. */ | |
1718 | ||
1719 | BFD_ASSERT (sgot != NULL); | |
1720 | if (sgot == NULL) | |
1721 | return bfd_reloc_notsupported; | |
9a5aca8c | 1722 | |
cedb70c5 | 1723 | /* If we are addressing a Thumb function, we need to adjust the |
ee29b9fb RE |
1724 | address by one, so that attempts to call the function pointer will |
1725 | correctly interpret it as Thumb code. */ | |
1726 | if (sym_flags == STT_ARM_TFUNC) | |
1727 | value += 1; | |
1728 | ||
252b5132 RH |
1729 | /* Note that sgot->output_offset is not involved in this |
1730 | calculation. We always want the start of .got. If we | |
1731 | define _GLOBAL_OFFSET_TABLE in a different way, as is | |
1732 | permitted by the ABI, we might have to change this | |
9b485d32 | 1733 | calculation. */ |
252b5132 | 1734 | value -= sgot->output_section->vma; |
f21f3fe0 | 1735 | return _bfd_final_link_relocate (howto, input_bfd, input_section, |
99e4ae17 AJ |
1736 | contents, rel->r_offset, value, |
1737 | (bfd_vma) 0); | |
252b5132 RH |
1738 | |
1739 | case R_ARM_GOTPC: | |
a7c10850 | 1740 | /* Use global offset table as symbol value. */ |
252b5132 | 1741 | BFD_ASSERT (sgot != NULL); |
f21f3fe0 | 1742 | |
252b5132 RH |
1743 | if (sgot == NULL) |
1744 | return bfd_reloc_notsupported; | |
1745 | ||
1746 | value = sgot->output_section->vma; | |
f21f3fe0 | 1747 | return _bfd_final_link_relocate (howto, input_bfd, input_section, |
99e4ae17 AJ |
1748 | contents, rel->r_offset, value, |
1749 | (bfd_vma) 0); | |
f21f3fe0 | 1750 | |
252b5132 RH |
1751 | case R_ARM_GOT32: |
1752 | /* Relocation is to the entry for this symbol in the | |
9b485d32 | 1753 | global offset table. */ |
252b5132 RH |
1754 | if (sgot == NULL) |
1755 | return bfd_reloc_notsupported; | |
f21f3fe0 | 1756 | |
252b5132 RH |
1757 | if (h != NULL) |
1758 | { | |
1759 | bfd_vma off; | |
5e681ec4 | 1760 | bfd_boolean dyn; |
f21f3fe0 | 1761 | |
252b5132 RH |
1762 | off = h->got.offset; |
1763 | BFD_ASSERT (off != (bfd_vma) -1); | |
5e681ec4 | 1764 | dyn = globals->root.dynamic_sections_created; |
f21f3fe0 | 1765 | |
5e681ec4 | 1766 | if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) |
50d6c878 | 1767 | || (info->shared |
5e681ec4 PB |
1768 | && SYMBOL_REFERENCES_LOCAL (info, h)) |
1769 | || (ELF_ST_VISIBILITY (h->other) | |
1770 | && h->root.type == bfd_link_hash_undefweak)) | |
252b5132 RH |
1771 | { |
1772 | /* This is actually a static link, or it is a -Bsymbolic link | |
1773 | and the symbol is defined locally. We must initialize this | |
1774 | entry in the global offset table. Since the offset must | |
1775 | always be a multiple of 4, we use the least significant bit | |
1776 | to record whether we have initialized it already. | |
f21f3fe0 | 1777 | |
252b5132 | 1778 | When doing a dynamic link, we create a .rel.got relocation |
f21f3fe0 | 1779 | entry to initialize the value. This is done in the |
9b485d32 | 1780 | finish_dynamic_symbol routine. */ |
252b5132 RH |
1781 | if ((off & 1) != 0) |
1782 | off &= ~1; | |
1783 | else | |
1784 | { | |
ee29b9fb RE |
1785 | /* If we are addressing a Thumb function, we need to |
1786 | adjust the address by one, so that attempts to | |
1787 | call the function pointer will correctly | |
1788 | interpret it as Thumb code. */ | |
1789 | if (sym_flags == STT_ARM_TFUNC) | |
1790 | value |= 1; | |
1791 | ||
252b5132 RH |
1792 | bfd_put_32 (output_bfd, value, sgot->contents + off); |
1793 | h->got.offset |= 1; | |
1794 | } | |
1795 | } | |
f21f3fe0 | 1796 | |
252b5132 RH |
1797 | value = sgot->output_offset + off; |
1798 | } | |
1799 | else | |
1800 | { | |
1801 | bfd_vma off; | |
f21f3fe0 | 1802 | |
252b5132 RH |
1803 | BFD_ASSERT (local_got_offsets != NULL && |
1804 | local_got_offsets[r_symndx] != (bfd_vma) -1); | |
f21f3fe0 | 1805 | |
252b5132 | 1806 | off = local_got_offsets[r_symndx]; |
f21f3fe0 | 1807 | |
252b5132 RH |
1808 | /* The offset must always be a multiple of 4. We use the |
1809 | least significant bit to record whether we have already | |
9b485d32 | 1810 | generated the necessary reloc. */ |
252b5132 RH |
1811 | if ((off & 1) != 0) |
1812 | off &= ~1; | |
1813 | else | |
1814 | { | |
1815 | bfd_put_32 (output_bfd, value, sgot->contents + off); | |
f21f3fe0 | 1816 | |
252b5132 RH |
1817 | if (info->shared) |
1818 | { | |
1819 | asection * srelgot; | |
947216bf AM |
1820 | Elf_Internal_Rela outrel; |
1821 | bfd_byte *loc; | |
f21f3fe0 | 1822 | |
252b5132 RH |
1823 | srelgot = bfd_get_section_by_name (dynobj, ".rel.got"); |
1824 | BFD_ASSERT (srelgot != NULL); | |
f21f3fe0 | 1825 | |
252b5132 | 1826 | outrel.r_offset = (sgot->output_section->vma |
f21f3fe0 | 1827 | + sgot->output_offset |
252b5132 RH |
1828 | + off); |
1829 | outrel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE); | |
947216bf AM |
1830 | loc = srelgot->contents; |
1831 | loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rel); | |
1832 | bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc); | |
252b5132 | 1833 | } |
f21f3fe0 | 1834 | |
252b5132 RH |
1835 | local_got_offsets[r_symndx] |= 1; |
1836 | } | |
f21f3fe0 | 1837 | |
252b5132 RH |
1838 | value = sgot->output_offset + off; |
1839 | } | |
9a5aca8c | 1840 | |
f21f3fe0 | 1841 | return _bfd_final_link_relocate (howto, input_bfd, input_section, |
99e4ae17 AJ |
1842 | contents, rel->r_offset, value, |
1843 | (bfd_vma) 0); | |
f21f3fe0 | 1844 | |
252b5132 RH |
1845 | case R_ARM_SBREL32: |
1846 | return bfd_reloc_notsupported; | |
1847 | ||
1848 | case R_ARM_AMP_VCALL9: | |
1849 | return bfd_reloc_notsupported; | |
1850 | ||
1851 | case R_ARM_RSBREL32: | |
1852 | return bfd_reloc_notsupported; | |
1853 | ||
1854 | case R_ARM_THM_RPC22: | |
1855 | return bfd_reloc_notsupported; | |
1856 | ||
1857 | case R_ARM_RREL32: | |
1858 | return bfd_reloc_notsupported; | |
1859 | ||
1860 | case R_ARM_RABS32: | |
1861 | return bfd_reloc_notsupported; | |
1862 | ||
1863 | case R_ARM_RPC24: | |
1864 | return bfd_reloc_notsupported; | |
1865 | ||
1866 | case R_ARM_RBASE: | |
1867 | return bfd_reloc_notsupported; | |
1868 | ||
1869 | default: | |
1870 | return bfd_reloc_notsupported; | |
1871 | } | |
1872 | } | |
1873 | ||
acf8aed4 | 1874 | #if USE_REL |
98c1d4aa NC |
1875 | /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */ |
1876 | static void | |
57e8b36a NC |
1877 | arm_add_to_rel (bfd * abfd, |
1878 | bfd_byte * address, | |
1879 | reloc_howto_type * howto, | |
1880 | bfd_signed_vma increment) | |
98c1d4aa | 1881 | { |
98c1d4aa NC |
1882 | bfd_signed_vma addend; |
1883 | ||
9a5aca8c | 1884 | if (howto->type == R_ARM_THM_PC22) |
98c1d4aa | 1885 | { |
9a5aca8c AM |
1886 | int upper_insn, lower_insn; |
1887 | int upper, lower; | |
98c1d4aa | 1888 | |
9a5aca8c AM |
1889 | upper_insn = bfd_get_16 (abfd, address); |
1890 | lower_insn = bfd_get_16 (abfd, address + 2); | |
1891 | upper = upper_insn & 0x7ff; | |
1892 | lower = lower_insn & 0x7ff; | |
1893 | ||
1894 | addend = (upper << 12) | (lower << 1); | |
ddda4409 | 1895 | addend += increment; |
9a5aca8c | 1896 | addend >>= 1; |
98c1d4aa | 1897 | |
9a5aca8c AM |
1898 | upper_insn = (upper_insn & 0xf800) | ((addend >> 11) & 0x7ff); |
1899 | lower_insn = (lower_insn & 0xf800) | (addend & 0x7ff); | |
1900 | ||
dc810e39 AM |
1901 | bfd_put_16 (abfd, (bfd_vma) upper_insn, address); |
1902 | bfd_put_16 (abfd, (bfd_vma) lower_insn, address + 2); | |
9a5aca8c AM |
1903 | } |
1904 | else | |
1905 | { | |
1906 | bfd_vma contents; | |
1907 | ||
1908 | contents = bfd_get_32 (abfd, address); | |
1909 | ||
1910 | /* Get the (signed) value from the instruction. */ | |
1911 | addend = contents & howto->src_mask; | |
1912 | if (addend & ((howto->src_mask + 1) >> 1)) | |
1913 | { | |
1914 | bfd_signed_vma mask; | |
1915 | ||
1916 | mask = -1; | |
1917 | mask &= ~ howto->src_mask; | |
1918 | addend |= mask; | |
1919 | } | |
1920 | ||
1921 | /* Add in the increment, (which is a byte value). */ | |
1922 | switch (howto->type) | |
1923 | { | |
1924 | default: | |
1925 | addend += increment; | |
1926 | break; | |
1927 | ||
1928 | case R_ARM_PC24: | |
1929 | addend <<= howto->size; | |
dc810e39 | 1930 | addend += increment; |
9a5aca8c AM |
1931 | |
1932 | /* Should we check for overflow here ? */ | |
1933 | ||
1934 | /* Drop any undesired bits. */ | |
1935 | addend >>= howto->rightshift; | |
1936 | break; | |
1937 | } | |
1938 | ||
1939 | contents = (contents & ~ howto->dst_mask) | (addend & howto->dst_mask); | |
1940 | ||
1941 | bfd_put_32 (abfd, contents, address); | |
ddda4409 | 1942 | } |
98c1d4aa NC |
1943 | } |
1944 | #endif /* USE_REL */ | |
252b5132 RH |
1945 | |
1946 | /* Relocate an ARM ELF section. */ | |
b34976b6 | 1947 | static bfd_boolean |
57e8b36a NC |
1948 | elf32_arm_relocate_section (bfd * output_bfd, |
1949 | struct bfd_link_info * info, | |
1950 | bfd * input_bfd, | |
1951 | asection * input_section, | |
1952 | bfd_byte * contents, | |
1953 | Elf_Internal_Rela * relocs, | |
1954 | Elf_Internal_Sym * local_syms, | |
1955 | asection ** local_sections) | |
252b5132 | 1956 | { |
b34976b6 AM |
1957 | Elf_Internal_Shdr *symtab_hdr; |
1958 | struct elf_link_hash_entry **sym_hashes; | |
1959 | Elf_Internal_Rela *rel; | |
1960 | Elf_Internal_Rela *relend; | |
1961 | const char *name; | |
252b5132 | 1962 | |
acf8aed4 | 1963 | #if !USE_REL |
1049f94e | 1964 | if (info->relocatable) |
b34976b6 | 1965 | return TRUE; |
b491616a AM |
1966 | #endif |
1967 | ||
252b5132 RH |
1968 | symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr; |
1969 | sym_hashes = elf_sym_hashes (input_bfd); | |
1970 | ||
1971 | rel = relocs; | |
1972 | relend = relocs + input_section->reloc_count; | |
1973 | for (; rel < relend; rel++) | |
1974 | { | |
ba96a88f NC |
1975 | int r_type; |
1976 | reloc_howto_type * howto; | |
1977 | unsigned long r_symndx; | |
1978 | Elf_Internal_Sym * sym; | |
1979 | asection * sec; | |
252b5132 | 1980 | struct elf_link_hash_entry * h; |
ba96a88f NC |
1981 | bfd_vma relocation; |
1982 | bfd_reloc_status_type r; | |
1983 | arelent bfd_reloc; | |
f21f3fe0 | 1984 | |
252b5132 | 1985 | r_symndx = ELF32_R_SYM (rel->r_info); |
ba96a88f | 1986 | r_type = ELF32_R_TYPE (rel->r_info); |
252b5132 | 1987 | |
ba96a88f NC |
1988 | if ( r_type == R_ARM_GNU_VTENTRY |
1989 | || r_type == R_ARM_GNU_VTINHERIT) | |
252b5132 RH |
1990 | continue; |
1991 | ||
dc810e39 | 1992 | elf32_arm_info_to_howto (input_bfd, & bfd_reloc, rel); |
ba96a88f | 1993 | howto = bfd_reloc.howto; |
252b5132 | 1994 | |
acf8aed4 | 1995 | #if USE_REL |
1049f94e | 1996 | if (info->relocatable) |
252b5132 | 1997 | { |
1049f94e | 1998 | /* This is a relocatable link. We don't have to change |
252b5132 RH |
1999 | anything, unless the reloc is against a section symbol, |
2000 | in which case we have to adjust according to where the | |
2001 | section symbol winds up in the output section. */ | |
2002 | if (r_symndx < symtab_hdr->sh_info) | |
2003 | { | |
2004 | sym = local_syms + r_symndx; | |
2005 | if (ELF_ST_TYPE (sym->st_info) == STT_SECTION) | |
2006 | { | |
2007 | sec = local_sections[r_symndx]; | |
98c1d4aa | 2008 | arm_add_to_rel (input_bfd, contents + rel->r_offset, |
dc810e39 AM |
2009 | howto, |
2010 | (bfd_signed_vma) (sec->output_offset | |
2011 | + sym->st_value)); | |
252b5132 RH |
2012 | } |
2013 | } | |
2014 | ||
2015 | continue; | |
2016 | } | |
b491616a | 2017 | #endif |
252b5132 RH |
2018 | |
2019 | /* This is a final link. */ | |
2020 | h = NULL; | |
2021 | sym = NULL; | |
2022 | sec = NULL; | |
9b485d32 | 2023 | |
252b5132 RH |
2024 | if (r_symndx < symtab_hdr->sh_info) |
2025 | { | |
2026 | sym = local_syms + r_symndx; | |
2027 | sec = local_sections[r_symndx]; | |
acf8aed4 | 2028 | #if USE_REL |
252b5132 RH |
2029 | relocation = (sec->output_section->vma |
2030 | + sec->output_offset | |
2031 | + sym->st_value); | |
f8df10f4 JJ |
2032 | if ((sec->flags & SEC_MERGE) |
2033 | && ELF_ST_TYPE (sym->st_info) == STT_SECTION) | |
2034 | { | |
2035 | asection *msec; | |
2036 | bfd_vma addend, value; | |
2037 | ||
2038 | if (howto->rightshift) | |
2039 | { | |
2040 | (*_bfd_error_handler) | |
d003868e AM |
2041 | (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"), |
2042 | input_bfd, input_section, | |
f8df10f4 | 2043 | (long) rel->r_offset, howto->name); |
b34976b6 | 2044 | return FALSE; |
f8df10f4 JJ |
2045 | } |
2046 | ||
2047 | value = bfd_get_32 (input_bfd, contents + rel->r_offset); | |
2048 | ||
2049 | /* Get the (signed) value from the instruction. */ | |
2050 | addend = value & howto->src_mask; | |
2051 | if (addend & ((howto->src_mask + 1) >> 1)) | |
2052 | { | |
2053 | bfd_signed_vma mask; | |
2054 | ||
2055 | mask = -1; | |
2056 | mask &= ~ howto->src_mask; | |
2057 | addend |= mask; | |
2058 | } | |
2059 | msec = sec; | |
2060 | addend = | |
c629eae0 | 2061 | _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend) |
f8df10f4 JJ |
2062 | - relocation; |
2063 | addend += msec->output_section->vma + msec->output_offset; | |
2064 | value = (value & ~ howto->dst_mask) | (addend & howto->dst_mask); | |
2065 | bfd_put_32 (input_bfd, value, contents + rel->r_offset); | |
2066 | } | |
2067 | #else | |
8517fae7 | 2068 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); |
f8df10f4 | 2069 | #endif |
252b5132 RH |
2070 | } |
2071 | else | |
2072 | { | |
560e09e9 NC |
2073 | bfd_boolean warned; |
2074 | bfd_boolean unresolved_reloc; | |
2075 | ||
b2a8e766 AM |
2076 | RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, |
2077 | r_symndx, symtab_hdr, sym_hashes, | |
2078 | h, sec, relocation, | |
2079 | unresolved_reloc, warned); | |
57e8b36a | 2080 | |
560e09e9 | 2081 | if (unresolved_reloc || relocation != 0) |
252b5132 | 2082 | { |
252b5132 | 2083 | /* In these cases, we don't need the relocation value. |
f21f3fe0 | 2084 | We check specially because in some obscure cases |
9b485d32 | 2085 | sec->output_section will be NULL. */ |
252b5132 RH |
2086 | switch (r_type) |
2087 | { | |
2088 | case R_ARM_PC24: | |
2089 | case R_ARM_ABS32: | |
6a360bf4 | 2090 | case R_ARM_THM_PC22: |
ecb2d096 DJ |
2091 | case R_ARM_PLT32: |
2092 | ||
252b5132 RH |
2093 | if (info->shared |
2094 | && ( | |
5e681ec4 | 2095 | (!info->symbolic && h->dynindx != -1) |
97eaf9de | 2096 | || (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0 |
252b5132 | 2097 | ) |
5e681ec4 | 2098 | && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT |
05924f36 PB |
2099 | && ((input_section->flags & SEC_ALLOC) != 0 |
2100 | /* DWARF will emit R_ARM_ABS32 relocations in its | |
2101 | sections against symbols defined externally | |
2102 | in shared libraries. We can't do anything | |
2103 | with them here. */ | |
2104 | || ((input_section->flags & SEC_DEBUGGING) != 0 | |
2105 | && (h->elf_link_hash_flags | |
2106 | & ELF_LINK_HASH_DEF_DYNAMIC) != 0)) | |
252b5132 | 2107 | ) |
560e09e9 | 2108 | relocation = 0; |
252b5132 | 2109 | break; |
f21f3fe0 | 2110 | |
252b5132 | 2111 | case R_ARM_GOTPC: |
560e09e9 | 2112 | relocation = 0; |
252b5132 | 2113 | break; |
f21f3fe0 | 2114 | |
252b5132 | 2115 | case R_ARM_GOT32: |
50d6c878 | 2116 | if ((WILL_CALL_FINISH_DYNAMIC_SYMBOL |
560e09e9 | 2117 | (elf_hash_table (info)->dynamic_sections_created, |
50d6c878 DJ |
2118 | info->shared, h)) |
2119 | && (!info->shared | |
252b5132 | 2120 | || (!info->symbolic && h->dynindx != -1) |
50d6c878 DJ |
2121 | || (h->elf_link_hash_flags |
2122 | & ELF_LINK_HASH_DEF_REGULAR) == 0)) | |
560e09e9 | 2123 | relocation = 0; |
252b5132 | 2124 | break; |
f21f3fe0 | 2125 | |
252b5132 | 2126 | default: |
560e09e9 NC |
2127 | if (unresolved_reloc) |
2128 | _bfd_error_handler | |
d003868e AM |
2129 | (_("%B(%A): warning: unresolvable relocation %d against symbol `%s'"), |
2130 | input_bfd, input_section, | |
560e09e9 | 2131 | r_type, |
d003868e | 2132 | h->root.root.string); |
560e09e9 | 2133 | break; |
252b5132 | 2134 | } |
252b5132 RH |
2135 | } |
2136 | } | |
2137 | ||
2138 | if (h != NULL) | |
2139 | name = h->root.root.string; | |
2140 | else | |
2141 | { | |
2142 | name = (bfd_elf_string_from_elf_section | |
2143 | (input_bfd, symtab_hdr->sh_link, sym->st_name)); | |
2144 | if (name == NULL || *name == '\0') | |
2145 | name = bfd_section_name (input_bfd, sec); | |
2146 | } | |
f21f3fe0 | 2147 | |
252b5132 RH |
2148 | r = elf32_arm_final_link_relocate (howto, input_bfd, output_bfd, |
2149 | input_section, contents, rel, | |
2150 | relocation, info, sec, name, | |
2151 | (h ? ELF_ST_TYPE (h->type) : | |
780a67af | 2152 | ELF_ST_TYPE (sym->st_info)), h); |
252b5132 RH |
2153 | |
2154 | if (r != bfd_reloc_ok) | |
2155 | { | |
2156 | const char * msg = (const char *) 0; | |
2157 | ||
2158 | switch (r) | |
2159 | { | |
2160 | case bfd_reloc_overflow: | |
cf919dfd PB |
2161 | /* If the overflowing reloc was to an undefined symbol, |
2162 | we have already printed one error message and there | |
2163 | is no point complaining again. */ | |
2164 | if ((! h || | |
2165 | h->root.type != bfd_link_hash_undefined) | |
2166 | && (!((*info->callbacks->reloc_overflow) | |
2167 | (info, name, howto->name, (bfd_vma) 0, | |
2168 | input_bfd, input_section, rel->r_offset)))) | |
b34976b6 | 2169 | return FALSE; |
252b5132 RH |
2170 | break; |
2171 | ||
2172 | case bfd_reloc_undefined: | |
2173 | if (!((*info->callbacks->undefined_symbol) | |
2174 | (info, name, input_bfd, input_section, | |
b34976b6 AM |
2175 | rel->r_offset, TRUE))) |
2176 | return FALSE; | |
252b5132 RH |
2177 | break; |
2178 | ||
2179 | case bfd_reloc_outofrange: | |
9b485d32 | 2180 | msg = _("internal error: out of range error"); |
252b5132 RH |
2181 | goto common_error; |
2182 | ||
2183 | case bfd_reloc_notsupported: | |
9b485d32 | 2184 | msg = _("internal error: unsupported relocation error"); |
252b5132 RH |
2185 | goto common_error; |
2186 | ||
2187 | case bfd_reloc_dangerous: | |
9b485d32 | 2188 | msg = _("internal error: dangerous error"); |
252b5132 RH |
2189 | goto common_error; |
2190 | ||
2191 | default: | |
9b485d32 | 2192 | msg = _("internal error: unknown error"); |
252b5132 RH |
2193 | /* fall through */ |
2194 | ||
2195 | common_error: | |
2196 | if (!((*info->callbacks->warning) | |
2197 | (info, msg, name, input_bfd, input_section, | |
2198 | rel->r_offset))) | |
b34976b6 | 2199 | return FALSE; |
252b5132 RH |
2200 | break; |
2201 | } | |
2202 | } | |
2203 | } | |
2204 | ||
b34976b6 | 2205 | return TRUE; |
252b5132 RH |
2206 | } |
2207 | ||
c178919b NC |
2208 | /* Set the right machine number. */ |
2209 | ||
2210 | static bfd_boolean | |
57e8b36a | 2211 | elf32_arm_object_p (bfd *abfd) |
c178919b | 2212 | { |
5a6c6817 | 2213 | unsigned int mach; |
57e8b36a | 2214 | |
5a6c6817 | 2215 | mach = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION); |
c178919b | 2216 | |
5a6c6817 NC |
2217 | if (mach != bfd_mach_arm_unknown) |
2218 | bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach); | |
2219 | ||
2220 | else if (elf_elfheader (abfd)->e_flags & EF_ARM_MAVERICK_FLOAT) | |
2221 | bfd_default_set_arch_mach (abfd, bfd_arch_arm, bfd_mach_arm_ep9312); | |
e16bb312 | 2222 | |
e16bb312 | 2223 | else |
5a6c6817 | 2224 | bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach); |
c178919b NC |
2225 | |
2226 | return TRUE; | |
2227 | } | |
2228 | ||
fc830a83 | 2229 | /* Function to keep ARM specific flags in the ELF header. */ |
b34976b6 | 2230 | static bfd_boolean |
57e8b36a | 2231 | elf32_arm_set_private_flags (bfd *abfd, flagword flags) |
252b5132 RH |
2232 | { |
2233 | if (elf_flags_init (abfd) | |
2234 | && elf_elfheader (abfd)->e_flags != flags) | |
2235 | { | |
fc830a83 NC |
2236 | if (EF_ARM_EABI_VERSION (flags) == EF_ARM_EABI_UNKNOWN) |
2237 | { | |
fd2ec330 | 2238 | if (flags & EF_ARM_INTERWORK) |
d003868e AM |
2239 | (*_bfd_error_handler) |
2240 | (_("Warning: Not setting interworking flag of %B since it has already been specified as non-interworking"), | |
2241 | abfd); | |
fc830a83 | 2242 | else |
d003868e AM |
2243 | _bfd_error_handler |
2244 | (_("Warning: Clearing the interworking flag of %B due to outside request"), | |
2245 | abfd); | |
fc830a83 | 2246 | } |
252b5132 RH |
2247 | } |
2248 | else | |
2249 | { | |
2250 | elf_elfheader (abfd)->e_flags = flags; | |
b34976b6 | 2251 | elf_flags_init (abfd) = TRUE; |
252b5132 RH |
2252 | } |
2253 | ||
b34976b6 | 2254 | return TRUE; |
252b5132 RH |
2255 | } |
2256 | ||
fc830a83 | 2257 | /* Copy backend specific data from one object module to another. */ |
9b485d32 | 2258 | |
b34976b6 | 2259 | static bfd_boolean |
57e8b36a | 2260 | elf32_arm_copy_private_bfd_data (bfd *ibfd, bfd *obfd) |
252b5132 RH |
2261 | { |
2262 | flagword in_flags; | |
2263 | flagword out_flags; | |
2264 | ||
fc830a83 | 2265 | if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour |
252b5132 | 2266 | || bfd_get_flavour (obfd) != bfd_target_elf_flavour) |
b34976b6 | 2267 | return TRUE; |
252b5132 | 2268 | |
fc830a83 | 2269 | in_flags = elf_elfheader (ibfd)->e_flags; |
252b5132 RH |
2270 | out_flags = elf_elfheader (obfd)->e_flags; |
2271 | ||
fc830a83 NC |
2272 | if (elf_flags_init (obfd) |
2273 | && EF_ARM_EABI_VERSION (out_flags) == EF_ARM_EABI_UNKNOWN | |
2274 | && in_flags != out_flags) | |
252b5132 | 2275 | { |
252b5132 | 2276 | /* Cannot mix APCS26 and APCS32 code. */ |
fd2ec330 | 2277 | if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26)) |
b34976b6 | 2278 | return FALSE; |
252b5132 RH |
2279 | |
2280 | /* Cannot mix float APCS and non-float APCS code. */ | |
fd2ec330 | 2281 | if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT)) |
b34976b6 | 2282 | return FALSE; |
252b5132 RH |
2283 | |
2284 | /* If the src and dest have different interworking flags | |
2285 | then turn off the interworking bit. */ | |
fd2ec330 | 2286 | if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK)) |
252b5132 | 2287 | { |
fd2ec330 | 2288 | if (out_flags & EF_ARM_INTERWORK) |
d003868e AM |
2289 | _bfd_error_handler |
2290 | (_("Warning: Clearing the interworking flag of %B because non-interworking code in %B has been linked with it"), | |
2291 | obfd, ibfd); | |
252b5132 | 2292 | |
fd2ec330 | 2293 | in_flags &= ~EF_ARM_INTERWORK; |
252b5132 | 2294 | } |
1006ba19 PB |
2295 | |
2296 | /* Likewise for PIC, though don't warn for this case. */ | |
fd2ec330 PB |
2297 | if ((in_flags & EF_ARM_PIC) != (out_flags & EF_ARM_PIC)) |
2298 | in_flags &= ~EF_ARM_PIC; | |
252b5132 RH |
2299 | } |
2300 | ||
2301 | elf_elfheader (obfd)->e_flags = in_flags; | |
b34976b6 | 2302 | elf_flags_init (obfd) = TRUE; |
252b5132 | 2303 | |
b34976b6 | 2304 | return TRUE; |
252b5132 RH |
2305 | } |
2306 | ||
2307 | /* Merge backend specific data from an object file to the output | |
2308 | object file when linking. */ | |
9b485d32 | 2309 | |
b34976b6 | 2310 | static bfd_boolean |
57e8b36a | 2311 | elf32_arm_merge_private_bfd_data (bfd * ibfd, bfd * obfd) |
252b5132 RH |
2312 | { |
2313 | flagword out_flags; | |
2314 | flagword in_flags; | |
b34976b6 | 2315 | bfd_boolean flags_compatible = TRUE; |
cf919dfd | 2316 | asection *sec; |
252b5132 | 2317 | |
9b485d32 | 2318 | /* Check if we have the same endianess. */ |
82e51918 | 2319 | if (! _bfd_generic_verify_endian_match (ibfd, obfd)) |
b34976b6 | 2320 | return FALSE; |
1fe494a5 | 2321 | |
252b5132 RH |
2322 | if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour |
2323 | || bfd_get_flavour (obfd) != bfd_target_elf_flavour) | |
b34976b6 | 2324 | return TRUE; |
252b5132 | 2325 | |
252b5132 RH |
2326 | /* The input BFD must have had its flags initialised. */ |
2327 | /* The following seems bogus to me -- The flags are initialized in | |
2328 | the assembler but I don't think an elf_flags_init field is | |
9b485d32 | 2329 | written into the object. */ |
252b5132 RH |
2330 | /* BFD_ASSERT (elf_flags_init (ibfd)); */ |
2331 | ||
2332 | in_flags = elf_elfheader (ibfd)->e_flags; | |
2333 | out_flags = elf_elfheader (obfd)->e_flags; | |
2334 | ||
2335 | if (!elf_flags_init (obfd)) | |
2336 | { | |
fe077fa6 NC |
2337 | /* If the input is the default architecture and had the default |
2338 | flags then do not bother setting the flags for the output | |
2339 | architecture, instead allow future merges to do this. If no | |
2340 | future merges ever set these flags then they will retain their | |
2341 | uninitialised values, which surprise surprise, correspond | |
252b5132 | 2342 | to the default values. */ |
fe077fa6 NC |
2343 | if (bfd_get_arch_info (ibfd)->the_default |
2344 | && elf_elfheader (ibfd)->e_flags == 0) | |
b34976b6 | 2345 | return TRUE; |
252b5132 | 2346 | |
b34976b6 | 2347 | elf_flags_init (obfd) = TRUE; |
252b5132 RH |
2348 | elf_elfheader (obfd)->e_flags = in_flags; |
2349 | ||
2350 | if (bfd_get_arch (obfd) == bfd_get_arch (ibfd) | |
2351 | && bfd_get_arch_info (obfd)->the_default) | |
2352 | return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd)); | |
2353 | ||
b34976b6 | 2354 | return TRUE; |
252b5132 RH |
2355 | } |
2356 | ||
5a6c6817 NC |
2357 | /* Determine what should happen if the input ARM architecture |
2358 | does not match the output ARM architecture. */ | |
2359 | if (! bfd_arm_merge_machines (ibfd, obfd)) | |
2360 | return FALSE; | |
e16bb312 | 2361 | |
1006ba19 | 2362 | /* Identical flags must be compatible. */ |
252b5132 | 2363 | if (in_flags == out_flags) |
b34976b6 | 2364 | return TRUE; |
252b5132 | 2365 | |
35a0f415 DJ |
2366 | /* Check to see if the input BFD actually contains any sections. If |
2367 | not, its flags may not have been initialised either, but it | |
2368 | cannot actually cause any incompatibility. Do not short-circuit | |
2369 | dynamic objects; their section list may be emptied by | |
d1f161ea | 2370 | elf_link_add_object_symbols. |
35a0f415 | 2371 | |
d1f161ea NC |
2372 | Also check to see if there are no code sections in the input. |
2373 | In this case there is no need to check for code specific flags. | |
2374 | XXX - do we need to worry about floating-point format compatability | |
2375 | in data sections ? */ | |
35a0f415 | 2376 | if (!(ibfd->flags & DYNAMIC)) |
cf919dfd | 2377 | { |
35a0f415 | 2378 | bfd_boolean null_input_bfd = TRUE; |
d1f161ea | 2379 | bfd_boolean only_data_sections = TRUE; |
35a0f415 DJ |
2380 | |
2381 | for (sec = ibfd->sections; sec != NULL; sec = sec->next) | |
cf919dfd | 2382 | { |
35a0f415 DJ |
2383 | /* Ignore synthetic glue sections. */ |
2384 | if (strcmp (sec->name, ".glue_7") | |
2385 | && strcmp (sec->name, ".glue_7t")) | |
2386 | { | |
d1f161ea NC |
2387 | if ((bfd_get_section_flags (ibfd, sec) |
2388 | & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS)) | |
2389 | == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS)) | |
2390 | only_data_sections = FALSE; | |
2391 | ||
35a0f415 DJ |
2392 | null_input_bfd = FALSE; |
2393 | break; | |
2394 | } | |
cf919dfd | 2395 | } |
d1f161ea NC |
2396 | |
2397 | if (null_input_bfd || only_data_sections) | |
35a0f415 | 2398 | return TRUE; |
cf919dfd | 2399 | } |
cf919dfd | 2400 | |
252b5132 | 2401 | /* Complain about various flag mismatches. */ |
fc830a83 NC |
2402 | if (EF_ARM_EABI_VERSION (in_flags) != EF_ARM_EABI_VERSION (out_flags)) |
2403 | { | |
d003868e AM |
2404 | _bfd_error_handler |
2405 | (_("ERROR: %B is compiled for EABI version %d, whereas %B is compiled for version %d"), | |
2406 | ibfd, obfd, | |
2407 | (in_flags & EF_ARM_EABIMASK) >> 24, | |
2408 | (out_flags & EF_ARM_EABIMASK) >> 24); | |
b34976b6 | 2409 | return FALSE; |
fc830a83 | 2410 | } |
252b5132 | 2411 | |
1006ba19 PB |
2412 | /* Not sure what needs to be checked for EABI versions >= 1. */ |
2413 | if (EF_ARM_EABI_VERSION (in_flags) == EF_ARM_EABI_UNKNOWN) | |
2414 | { | |
fd2ec330 | 2415 | if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26)) |
1006ba19 | 2416 | { |
d003868e AM |
2417 | _bfd_error_handler |
2418 | (_("ERROR: %B is compiled for APCS-%d, whereas target %B uses APCS-%d"), | |
2419 | ibfd, obfd, | |
2420 | in_flags & EF_ARM_APCS_26 ? 26 : 32, | |
2421 | out_flags & EF_ARM_APCS_26 ? 26 : 32); | |
b34976b6 | 2422 | flags_compatible = FALSE; |
1006ba19 | 2423 | } |
252b5132 | 2424 | |
fd2ec330 | 2425 | if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT)) |
1006ba19 | 2426 | { |
5eefb65f | 2427 | if (in_flags & EF_ARM_APCS_FLOAT) |
d003868e AM |
2428 | _bfd_error_handler |
2429 | (_("ERROR: %B passes floats in float registers, whereas %B passes them in integer registers"), | |
2430 | ibfd, obfd); | |
5eefb65f | 2431 | else |
d003868e AM |
2432 | _bfd_error_handler |
2433 | (_("ERROR: %B passes floats in integer registers, whereas %B passes them in float registers"), | |
2434 | ibfd, obfd); | |
63b0f745 | 2435 | |
b34976b6 | 2436 | flags_compatible = FALSE; |
1006ba19 | 2437 | } |
252b5132 | 2438 | |
96a846ea | 2439 | if ((in_flags & EF_ARM_VFP_FLOAT) != (out_flags & EF_ARM_VFP_FLOAT)) |
1006ba19 | 2440 | { |
96a846ea | 2441 | if (in_flags & EF_ARM_VFP_FLOAT) |
d003868e AM |
2442 | _bfd_error_handler |
2443 | (_("ERROR: %B uses VFP instructions, whereas %B does not"), | |
2444 | ibfd, obfd); | |
5eefb65f | 2445 | else |
d003868e AM |
2446 | _bfd_error_handler |
2447 | (_("ERROR: %B uses FPA instructions, whereas %B does not"), | |
2448 | ibfd, obfd); | |
fde78edd NC |
2449 | |
2450 | flags_compatible = FALSE; | |
2451 | } | |
2452 | ||
2453 | if ((in_flags & EF_ARM_MAVERICK_FLOAT) != (out_flags & EF_ARM_MAVERICK_FLOAT)) | |
2454 | { | |
2455 | if (in_flags & EF_ARM_MAVERICK_FLOAT) | |
d003868e AM |
2456 | _bfd_error_handler |
2457 | (_("ERROR: %B uses Maverick instructions, whereas %B does not"), | |
2458 | ibfd, obfd); | |
fde78edd | 2459 | else |
d003868e AM |
2460 | _bfd_error_handler |
2461 | (_("ERROR: %B does not use Maverick instructions, whereas %B does"), | |
2462 | ibfd, obfd); | |
63b0f745 | 2463 | |
b34976b6 | 2464 | flags_compatible = FALSE; |
1006ba19 | 2465 | } |
96a846ea RE |
2466 | |
2467 | #ifdef EF_ARM_SOFT_FLOAT | |
2468 | if ((in_flags & EF_ARM_SOFT_FLOAT) != (out_flags & EF_ARM_SOFT_FLOAT)) | |
2469 | { | |
2470 | /* We can allow interworking between code that is VFP format | |
2471 | layout, and uses either soft float or integer regs for | |
2472 | passing floating point arguments and results. We already | |
2473 | know that the APCS_FLOAT flags match; similarly for VFP | |
2474 | flags. */ | |
2475 | if ((in_flags & EF_ARM_APCS_FLOAT) != 0 | |
2476 | || (in_flags & EF_ARM_VFP_FLOAT) == 0) | |
2477 | { | |
2478 | if (in_flags & EF_ARM_SOFT_FLOAT) | |
d003868e AM |
2479 | _bfd_error_handler |
2480 | (_("ERROR: %B uses software FP, whereas %B uses hardware FP"), | |
2481 | ibfd, obfd); | |
96a846ea | 2482 | else |
d003868e AM |
2483 | _bfd_error_handler |
2484 | (_("ERROR: %B uses hardware FP, whereas %B uses software FP"), | |
2485 | ibfd, obfd); | |
96a846ea | 2486 | |
b34976b6 | 2487 | flags_compatible = FALSE; |
96a846ea RE |
2488 | } |
2489 | } | |
ee43f35e | 2490 | #endif |
252b5132 | 2491 | |
1006ba19 | 2492 | /* Interworking mismatch is only a warning. */ |
fd2ec330 | 2493 | if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK)) |
8f615d07 | 2494 | { |
e3c8793a NC |
2495 | if (in_flags & EF_ARM_INTERWORK) |
2496 | { | |
d003868e AM |
2497 | _bfd_error_handler |
2498 | (_("Warning: %B supports interworking, whereas %B does not"), | |
2499 | ibfd, obfd); | |
e3c8793a NC |
2500 | } |
2501 | else | |
2502 | { | |
d003868e AM |
2503 | _bfd_error_handler |
2504 | (_("Warning: %B does not support interworking, whereas %B does"), | |
2505 | ibfd, obfd); | |
e3c8793a | 2506 | } |
8f615d07 | 2507 | } |
252b5132 | 2508 | } |
63b0f745 | 2509 | |
1006ba19 | 2510 | return flags_compatible; |
252b5132 RH |
2511 | } |
2512 | ||
9b485d32 NC |
2513 | /* Display the flags field. */ |
2514 | ||
b34976b6 | 2515 | static bfd_boolean |
57e8b36a | 2516 | elf32_arm_print_private_bfd_data (bfd *abfd, void * ptr) |
252b5132 | 2517 | { |
fc830a83 NC |
2518 | FILE * file = (FILE *) ptr; |
2519 | unsigned long flags; | |
252b5132 RH |
2520 | |
2521 | BFD_ASSERT (abfd != NULL && ptr != NULL); | |
2522 | ||
2523 | /* Print normal ELF private data. */ | |
2524 | _bfd_elf_print_private_bfd_data (abfd, ptr); | |
2525 | ||
fc830a83 | 2526 | flags = elf_elfheader (abfd)->e_flags; |
9b485d32 NC |
2527 | /* Ignore init flag - it may not be set, despite the flags field |
2528 | containing valid data. */ | |
252b5132 RH |
2529 | |
2530 | /* xgettext:c-format */ | |
9b485d32 | 2531 | fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags); |
252b5132 | 2532 | |
fc830a83 NC |
2533 | switch (EF_ARM_EABI_VERSION (flags)) |
2534 | { | |
2535 | case EF_ARM_EABI_UNKNOWN: | |
4cc11e76 | 2536 | /* The following flag bits are GNU extensions and not part of the |
fc830a83 NC |
2537 | official ARM ELF extended ABI. Hence they are only decoded if |
2538 | the EABI version is not set. */ | |
fd2ec330 | 2539 | if (flags & EF_ARM_INTERWORK) |
9b485d32 | 2540 | fprintf (file, _(" [interworking enabled]")); |
9a5aca8c | 2541 | |
fd2ec330 | 2542 | if (flags & EF_ARM_APCS_26) |
6c571f00 | 2543 | fprintf (file, " [APCS-26]"); |
fc830a83 | 2544 | else |
6c571f00 | 2545 | fprintf (file, " [APCS-32]"); |
9a5aca8c | 2546 | |
96a846ea RE |
2547 | if (flags & EF_ARM_VFP_FLOAT) |
2548 | fprintf (file, _(" [VFP float format]")); | |
fde78edd NC |
2549 | else if (flags & EF_ARM_MAVERICK_FLOAT) |
2550 | fprintf (file, _(" [Maverick float format]")); | |
96a846ea RE |
2551 | else |
2552 | fprintf (file, _(" [FPA float format]")); | |
2553 | ||
fd2ec330 | 2554 | if (flags & EF_ARM_APCS_FLOAT) |
9b485d32 | 2555 | fprintf (file, _(" [floats passed in float registers]")); |
9a5aca8c | 2556 | |
fd2ec330 | 2557 | if (flags & EF_ARM_PIC) |
9b485d32 | 2558 | fprintf (file, _(" [position independent]")); |
fc830a83 | 2559 | |
fd2ec330 | 2560 | if (flags & EF_ARM_NEW_ABI) |
9b485d32 | 2561 | fprintf (file, _(" [new ABI]")); |
9a5aca8c | 2562 | |
fd2ec330 | 2563 | if (flags & EF_ARM_OLD_ABI) |
9b485d32 | 2564 | fprintf (file, _(" [old ABI]")); |
9a5aca8c | 2565 | |
fd2ec330 | 2566 | if (flags & EF_ARM_SOFT_FLOAT) |
9b485d32 | 2567 | fprintf (file, _(" [software FP]")); |
9a5aca8c | 2568 | |
96a846ea RE |
2569 | flags &= ~(EF_ARM_INTERWORK | EF_ARM_APCS_26 | EF_ARM_APCS_FLOAT |
2570 | | EF_ARM_PIC | EF_ARM_NEW_ABI | EF_ARM_OLD_ABI | |
fde78edd NC |
2571 | | EF_ARM_SOFT_FLOAT | EF_ARM_VFP_FLOAT |
2572 | | EF_ARM_MAVERICK_FLOAT); | |
fc830a83 | 2573 | break; |
9a5aca8c | 2574 | |
fc830a83 | 2575 | case EF_ARM_EABI_VER1: |
9b485d32 | 2576 | fprintf (file, _(" [Version1 EABI]")); |
9a5aca8c | 2577 | |
fc830a83 | 2578 | if (flags & EF_ARM_SYMSARESORTED) |
9b485d32 | 2579 | fprintf (file, _(" [sorted symbol table]")); |
fc830a83 | 2580 | else |
9b485d32 | 2581 | fprintf (file, _(" [unsorted symbol table]")); |
9a5aca8c | 2582 | |
fc830a83 NC |
2583 | flags &= ~ EF_ARM_SYMSARESORTED; |
2584 | break; | |
9a5aca8c | 2585 | |
fd2ec330 PB |
2586 | case EF_ARM_EABI_VER2: |
2587 | fprintf (file, _(" [Version2 EABI]")); | |
2588 | ||
2589 | if (flags & EF_ARM_SYMSARESORTED) | |
2590 | fprintf (file, _(" [sorted symbol table]")); | |
2591 | else | |
2592 | fprintf (file, _(" [unsorted symbol table]")); | |
2593 | ||
2594 | if (flags & EF_ARM_DYNSYMSUSESEGIDX) | |
2595 | fprintf (file, _(" [dynamic symbols use segment index]")); | |
2596 | ||
2597 | if (flags & EF_ARM_MAPSYMSFIRST) | |
2598 | fprintf (file, _(" [mapping symbols precede others]")); | |
2599 | ||
99e4ae17 | 2600 | flags &= ~(EF_ARM_SYMSARESORTED | EF_ARM_DYNSYMSUSESEGIDX |
fd2ec330 PB |
2601 | | EF_ARM_MAPSYMSFIRST); |
2602 | break; | |
2603 | ||
d507cf36 PB |
2604 | case EF_ARM_EABI_VER3: |
2605 | fprintf (file, _(" [Version3 EABI]")); | |
2606 | ||
2607 | if (flags & EF_ARM_BE8) | |
2608 | fprintf (file, _(" [BE8]")); | |
2609 | ||
2610 | if (flags & EF_ARM_LE8) | |
2611 | fprintf (file, _(" [LE8]")); | |
2612 | ||
2613 | flags &= ~(EF_ARM_LE8 | EF_ARM_BE8); | |
2614 | break; | |
2615 | ||
fc830a83 | 2616 | default: |
9b485d32 | 2617 | fprintf (file, _(" <EABI version unrecognised>")); |
fc830a83 NC |
2618 | break; |
2619 | } | |
252b5132 | 2620 | |
fc830a83 | 2621 | flags &= ~ EF_ARM_EABIMASK; |
252b5132 | 2622 | |
fc830a83 | 2623 | if (flags & EF_ARM_RELEXEC) |
9b485d32 | 2624 | fprintf (file, _(" [relocatable executable]")); |
252b5132 | 2625 | |
fc830a83 | 2626 | if (flags & EF_ARM_HASENTRY) |
9b485d32 | 2627 | fprintf (file, _(" [has entry point]")); |
252b5132 | 2628 | |
fc830a83 NC |
2629 | flags &= ~ (EF_ARM_RELEXEC | EF_ARM_HASENTRY); |
2630 | ||
2631 | if (flags) | |
9b485d32 | 2632 | fprintf (file, _("<Unrecognised flag bits set>")); |
9a5aca8c | 2633 | |
252b5132 RH |
2634 | fputc ('\n', file); |
2635 | ||
b34976b6 | 2636 | return TRUE; |
252b5132 RH |
2637 | } |
2638 | ||
2639 | static int | |
57e8b36a | 2640 | elf32_arm_get_symbol_type (Elf_Internal_Sym * elf_sym, int type) |
252b5132 | 2641 | { |
2f0ca46a NC |
2642 | switch (ELF_ST_TYPE (elf_sym->st_info)) |
2643 | { | |
2644 | case STT_ARM_TFUNC: | |
2645 | return ELF_ST_TYPE (elf_sym->st_info); | |
ce855c42 | 2646 | |
2f0ca46a NC |
2647 | case STT_ARM_16BIT: |
2648 | /* If the symbol is not an object, return the STT_ARM_16BIT flag. | |
2649 | This allows us to distinguish between data used by Thumb instructions | |
2650 | and non-data (which is probably code) inside Thumb regions of an | |
2651 | executable. */ | |
2652 | if (type != STT_OBJECT) | |
2653 | return ELF_ST_TYPE (elf_sym->st_info); | |
2654 | break; | |
9a5aca8c | 2655 | |
ce855c42 NC |
2656 | default: |
2657 | break; | |
2f0ca46a NC |
2658 | } |
2659 | ||
2660 | return type; | |
252b5132 | 2661 | } |
f21f3fe0 | 2662 | |
252b5132 | 2663 | static asection * |
57e8b36a NC |
2664 | elf32_arm_gc_mark_hook (asection * sec, |
2665 | struct bfd_link_info * info ATTRIBUTE_UNUSED, | |
2666 | Elf_Internal_Rela * rel, | |
2667 | struct elf_link_hash_entry * h, | |
2668 | Elf_Internal_Sym * sym) | |
252b5132 RH |
2669 | { |
2670 | if (h != NULL) | |
2671 | { | |
2672 | switch (ELF32_R_TYPE (rel->r_info)) | |
2673 | { | |
2674 | case R_ARM_GNU_VTINHERIT: | |
2675 | case R_ARM_GNU_VTENTRY: | |
2676 | break; | |
2677 | ||
2678 | default: | |
2679 | switch (h->root.type) | |
2680 | { | |
2681 | case bfd_link_hash_defined: | |
2682 | case bfd_link_hash_defweak: | |
2683 | return h->root.u.def.section; | |
2684 | ||
2685 | case bfd_link_hash_common: | |
2686 | return h->root.u.c.p->section; | |
e049a0de ILT |
2687 | |
2688 | default: | |
2689 | break; | |
252b5132 RH |
2690 | } |
2691 | } | |
2692 | } | |
2693 | else | |
1e2f5b6e | 2694 | return bfd_section_from_elf_index (sec->owner, sym->st_shndx); |
9ad5cbcf | 2695 | |
252b5132 RH |
2696 | return NULL; |
2697 | } | |
2698 | ||
780a67af NC |
2699 | /* Update the got entry reference counts for the section being removed. */ |
2700 | ||
b34976b6 | 2701 | static bfd_boolean |
57e8b36a NC |
2702 | elf32_arm_gc_sweep_hook (bfd * abfd ATTRIBUTE_UNUSED, |
2703 | struct bfd_link_info * info ATTRIBUTE_UNUSED, | |
2704 | asection * sec ATTRIBUTE_UNUSED, | |
2705 | const Elf_Internal_Rela * relocs ATTRIBUTE_UNUSED) | |
252b5132 | 2706 | { |
5e681ec4 PB |
2707 | Elf_Internal_Shdr *symtab_hdr; |
2708 | struct elf_link_hash_entry **sym_hashes; | |
2709 | bfd_signed_vma *local_got_refcounts; | |
2710 | const Elf_Internal_Rela *rel, *relend; | |
2711 | unsigned long r_symndx; | |
2712 | struct elf_link_hash_entry *h; | |
2713 | ||
2714 | elf_section_data (sec)->local_dynrel = NULL; | |
2715 | ||
2716 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; | |
2717 | sym_hashes = elf_sym_hashes (abfd); | |
2718 | local_got_refcounts = elf_local_got_refcounts (abfd); | |
2719 | ||
2720 | relend = relocs + sec->reloc_count; | |
2721 | for (rel = relocs; rel < relend; rel++) | |
2722 | switch (ELF32_R_TYPE (rel->r_info)) | |
2723 | { | |
2724 | case R_ARM_GOT32: | |
2725 | r_symndx = ELF32_R_SYM (rel->r_info); | |
2726 | if (r_symndx >= symtab_hdr->sh_info) | |
2727 | { | |
2728 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
2729 | if (h->got.refcount > 0) | |
2730 | h->got.refcount -= 1; | |
2731 | } | |
2732 | else if (local_got_refcounts != NULL) | |
2733 | { | |
2734 | if (local_got_refcounts[r_symndx] > 0) | |
2735 | local_got_refcounts[r_symndx] -= 1; | |
2736 | } | |
2737 | break; | |
2738 | ||
2739 | case R_ARM_ABS32: | |
2740 | case R_ARM_REL32: | |
2741 | case R_ARM_PC24: | |
7359ea65 | 2742 | case R_ARM_PLT32: |
5e681ec4 PB |
2743 | r_symndx = ELF32_R_SYM (rel->r_info); |
2744 | if (r_symndx >= symtab_hdr->sh_info) | |
2745 | { | |
2746 | struct elf32_arm_link_hash_entry *eh; | |
2747 | struct elf32_arm_relocs_copied **pp; | |
2748 | struct elf32_arm_relocs_copied *p; | |
2749 | ||
2750 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
2751 | ||
7359ea65 | 2752 | if (h->plt.refcount > 0) |
5e681ec4 PB |
2753 | h->plt.refcount -= 1; |
2754 | ||
7359ea65 DJ |
2755 | if (ELF32_R_TYPE (rel->r_info) == R_ARM_ABS32 |
2756 | || ELF32_R_TYPE (rel->r_info) == R_ARM_REL32) | |
2757 | { | |
2758 | eh = (struct elf32_arm_link_hash_entry *) h; | |
5e681ec4 | 2759 | |
7359ea65 DJ |
2760 | for (pp = &eh->relocs_copied; (p = *pp) != NULL; |
2761 | pp = &p->next) | |
2762 | if (p->section == sec) | |
2763 | { | |
2764 | p->count -= 1; | |
2765 | if (p->count == 0) | |
2766 | *pp = p->next; | |
2767 | break; | |
2768 | } | |
2769 | } | |
5e681ec4 PB |
2770 | } |
2771 | break; | |
2772 | ||
2773 | default: | |
2774 | break; | |
2775 | } | |
2776 | ||
b34976b6 | 2777 | return TRUE; |
252b5132 RH |
2778 | } |
2779 | ||
780a67af NC |
2780 | /* Look through the relocs for a section during the first phase. */ |
2781 | ||
b34976b6 | 2782 | static bfd_boolean |
57e8b36a NC |
2783 | elf32_arm_check_relocs (bfd *abfd, struct bfd_link_info *info, |
2784 | asection *sec, const Elf_Internal_Rela *relocs) | |
252b5132 | 2785 | { |
b34976b6 AM |
2786 | Elf_Internal_Shdr *symtab_hdr; |
2787 | struct elf_link_hash_entry **sym_hashes; | |
2788 | struct elf_link_hash_entry **sym_hashes_end; | |
2789 | const Elf_Internal_Rela *rel; | |
2790 | const Elf_Internal_Rela *rel_end; | |
2791 | bfd *dynobj; | |
5e681ec4 | 2792 | asection *sreloc; |
b34976b6 | 2793 | bfd_vma *local_got_offsets; |
5e681ec4 | 2794 | struct elf32_arm_link_hash_table *htab; |
9a5aca8c | 2795 | |
1049f94e | 2796 | if (info->relocatable) |
b34976b6 | 2797 | return TRUE; |
9a5aca8c | 2798 | |
5e681ec4 PB |
2799 | htab = elf32_arm_hash_table (info); |
2800 | sreloc = NULL; | |
9a5aca8c | 2801 | |
252b5132 RH |
2802 | dynobj = elf_hash_table (info)->dynobj; |
2803 | local_got_offsets = elf_local_got_offsets (abfd); | |
f21f3fe0 | 2804 | |
252b5132 RH |
2805 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
2806 | sym_hashes = elf_sym_hashes (abfd); | |
9b485d32 NC |
2807 | sym_hashes_end = sym_hashes |
2808 | + symtab_hdr->sh_size / sizeof (Elf32_External_Sym); | |
2809 | ||
252b5132 RH |
2810 | if (!elf_bad_symtab (abfd)) |
2811 | sym_hashes_end -= symtab_hdr->sh_info; | |
9b485d32 | 2812 | |
252b5132 RH |
2813 | rel_end = relocs + sec->reloc_count; |
2814 | for (rel = relocs; rel < rel_end; rel++) | |
2815 | { | |
2816 | struct elf_link_hash_entry *h; | |
2817 | unsigned long r_symndx; | |
9a5aca8c | 2818 | |
252b5132 RH |
2819 | r_symndx = ELF32_R_SYM (rel->r_info); |
2820 | if (r_symndx < symtab_hdr->sh_info) | |
2821 | h = NULL; | |
2822 | else | |
2823 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | |
9a5aca8c | 2824 | |
252b5132 RH |
2825 | switch (ELF32_R_TYPE (rel->r_info)) |
2826 | { | |
5e681ec4 PB |
2827 | case R_ARM_GOT32: |
2828 | /* This symbol requires a global offset table entry. */ | |
252b5132 RH |
2829 | if (h != NULL) |
2830 | { | |
5e681ec4 | 2831 | h->got.refcount++; |
252b5132 RH |
2832 | } |
2833 | else | |
2834 | { | |
5e681ec4 PB |
2835 | bfd_signed_vma *local_got_refcounts; |
2836 | ||
2837 | /* This is a global offset table entry for a local symbol. */ | |
2838 | local_got_refcounts = elf_local_got_refcounts (abfd); | |
2839 | if (local_got_refcounts == NULL) | |
252b5132 | 2840 | { |
dc810e39 | 2841 | bfd_size_type size; |
252b5132 | 2842 | |
dc810e39 | 2843 | size = symtab_hdr->sh_info; |
57e8b36a NC |
2844 | size *= (sizeof (bfd_signed_vma) + sizeof (char)); |
2845 | local_got_refcounts = bfd_zalloc (abfd, size); | |
5e681ec4 | 2846 | if (local_got_refcounts == NULL) |
b34976b6 | 2847 | return FALSE; |
5e681ec4 | 2848 | elf_local_got_refcounts (abfd) = local_got_refcounts; |
252b5132 | 2849 | } |
5e681ec4 | 2850 | local_got_refcounts[r_symndx] += 1; |
252b5132 | 2851 | } |
252b5132 RH |
2852 | break; |
2853 | ||
5e681ec4 PB |
2854 | case R_ARM_GOTOFF: |
2855 | case R_ARM_GOTPC: | |
2856 | if (htab->sgot == NULL) | |
2857 | { | |
2858 | if (htab->root.dynobj == NULL) | |
2859 | htab->root.dynobj = abfd; | |
2860 | if (!create_got_section (htab->root.dynobj, info)) | |
2861 | return FALSE; | |
2862 | } | |
252b5132 RH |
2863 | break; |
2864 | ||
2865 | case R_ARM_ABS32: | |
2866 | case R_ARM_REL32: | |
2867 | case R_ARM_PC24: | |
7359ea65 DJ |
2868 | case R_ARM_PLT32: |
2869 | if (h != NULL) | |
5e681ec4 PB |
2870 | { |
2871 | /* If this reloc is in a read-only section, we might | |
2872 | need a copy reloc. We can't check reliably at this | |
2873 | stage whether the section is read-only, as input | |
2874 | sections have not yet been mapped to output sections. | |
2875 | Tentatively set the flag for now, and correct in | |
2876 | adjust_dynamic_symbol. */ | |
7359ea65 DJ |
2877 | if (!info->shared) |
2878 | h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF; | |
2879 | ||
5e681ec4 | 2880 | /* We may need a .plt entry if the function this reloc |
c84cd8ee DJ |
2881 | refers to is in a different object. We can't tell for |
2882 | sure yet, because something later might force the | |
2883 | symbol local. */ | |
7359ea65 DJ |
2884 | if (ELF32_R_TYPE (rel->r_info) == R_ARM_PC24 |
2885 | || ELF32_R_TYPE (rel->r_info) == R_ARM_PLT32) | |
4f199be3 DJ |
2886 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; |
2887 | ||
2888 | /* If we create a PLT entry, this relocation will reference | |
2889 | it, even if it's an ABS32 relocation. */ | |
2890 | h->plt.refcount += 1; | |
5e681ec4 PB |
2891 | } |
2892 | ||
252b5132 RH |
2893 | /* If we are creating a shared library, and this is a reloc |
2894 | against a global symbol, or a non PC relative reloc | |
2895 | against a local symbol, then we need to copy the reloc | |
2896 | into the shared library. However, if we are linking with | |
2897 | -Bsymbolic, we do not need to copy a reloc against a | |
2898 | global symbol which is defined in an object we are | |
2899 | including in the link (i.e., DEF_REGULAR is set). At | |
2900 | this point we have not seen all the input files, so it is | |
2901 | possible that DEF_REGULAR is not set now but will be set | |
2902 | later (it is never cleared). We account for that | |
2903 | possibility below by storing information in the | |
5e681ec4 | 2904 | relocs_copied field of the hash table entry. */ |
252b5132 | 2905 | if (info->shared |
5e681ec4 | 2906 | && (sec->flags & SEC_ALLOC) != 0 |
7359ea65 | 2907 | && ((ELF32_R_TYPE (rel->r_info) != R_ARM_PC24 |
955af222 PB |
2908 | && ELF32_R_TYPE (rel->r_info) != R_ARM_PLT32 |
2909 | && ELF32_R_TYPE (rel->r_info) != R_ARM_REL32) | |
5e681ec4 PB |
2910 | || (h != NULL |
2911 | && (! info->symbolic | |
2912 | || (h->elf_link_hash_flags | |
2913 | & ELF_LINK_HASH_DEF_REGULAR) == 0)))) | |
252b5132 | 2914 | { |
5e681ec4 PB |
2915 | struct elf32_arm_relocs_copied *p, **head; |
2916 | ||
252b5132 RH |
2917 | /* When creating a shared object, we must copy these |
2918 | reloc types into the output file. We create a reloc | |
2919 | section in dynobj and make room for this reloc. */ | |
2920 | if (sreloc == NULL) | |
2921 | { | |
2922 | const char * name; | |
2923 | ||
2924 | name = (bfd_elf_string_from_elf_section | |
2925 | (abfd, | |
2926 | elf_elfheader (abfd)->e_shstrndx, | |
2927 | elf_section_data (sec)->rel_hdr.sh_name)); | |
2928 | if (name == NULL) | |
b34976b6 | 2929 | return FALSE; |
252b5132 RH |
2930 | |
2931 | BFD_ASSERT (strncmp (name, ".rel", 4) == 0 | |
99e4ae17 | 2932 | && strcmp (bfd_get_section_name (abfd, sec), |
252b5132 RH |
2933 | name + 4) == 0); |
2934 | ||
2935 | sreloc = bfd_get_section_by_name (dynobj, name); | |
2936 | if (sreloc == NULL) | |
2937 | { | |
2938 | flagword flags; | |
2939 | ||
2940 | sreloc = bfd_make_section (dynobj, name); | |
2941 | flags = (SEC_HAS_CONTENTS | SEC_READONLY | |
2942 | | SEC_IN_MEMORY | SEC_LINKER_CREATED); | |
e5a52504 MM |
2943 | if ((sec->flags & SEC_ALLOC) != 0 |
2944 | /* BPABI objects never have dynamic | |
2945 | relocations mapped. */ | |
2946 | && !htab->symbian_p) | |
252b5132 RH |
2947 | flags |= SEC_ALLOC | SEC_LOAD; |
2948 | if (sreloc == NULL | |
2949 | || ! bfd_set_section_flags (dynobj, sreloc, flags) | |
2950 | || ! bfd_set_section_alignment (dynobj, sreloc, 2)) | |
b34976b6 | 2951 | return FALSE; |
252b5132 | 2952 | } |
5e681ec4 PB |
2953 | |
2954 | elf_section_data (sec)->sreloc = sreloc; | |
252b5132 RH |
2955 | } |
2956 | ||
5e681ec4 PB |
2957 | /* If this is a global symbol, we count the number of |
2958 | relocations we need for this symbol. */ | |
2959 | if (h != NULL) | |
252b5132 | 2960 | { |
5e681ec4 PB |
2961 | head = &((struct elf32_arm_link_hash_entry *) h)->relocs_copied; |
2962 | } | |
2963 | else | |
2964 | { | |
2965 | /* Track dynamic relocs needed for local syms too. | |
2966 | We really need local syms available to do this | |
2967 | easily. Oh well. */ | |
57e8b36a | 2968 | |
5e681ec4 PB |
2969 | asection *s; |
2970 | s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, | |
2971 | sec, r_symndx); | |
2972 | if (s == NULL) | |
2973 | return FALSE; | |
57e8b36a | 2974 | |
5e681ec4 PB |
2975 | head = ((struct elf32_arm_relocs_copied **) |
2976 | &elf_section_data (s)->local_dynrel); | |
2977 | } | |
57e8b36a | 2978 | |
5e681ec4 PB |
2979 | p = *head; |
2980 | if (p == NULL || p->section != sec) | |
2981 | { | |
2982 | bfd_size_type amt = sizeof *p; | |
57e8b36a | 2983 | |
5e681ec4 | 2984 | p = bfd_alloc (htab->root.dynobj, amt); |
252b5132 | 2985 | if (p == NULL) |
5e681ec4 PB |
2986 | return FALSE; |
2987 | p->next = *head; | |
2988 | *head = p; | |
2989 | p->section = sec; | |
2990 | p->count = 0; | |
252b5132 | 2991 | } |
57e8b36a | 2992 | |
7359ea65 DJ |
2993 | if (ELF32_R_TYPE (rel->r_info) == R_ARM_ABS32 |
2994 | || ELF32_R_TYPE (rel->r_info) == R_ARM_REL32) | |
2995 | p->count += 1; | |
252b5132 RH |
2996 | } |
2997 | break; | |
2998 | ||
2999 | /* This relocation describes the C++ object vtable hierarchy. | |
3000 | Reconstruct it for later use during GC. */ | |
3001 | case R_ARM_GNU_VTINHERIT: | |
c152c796 | 3002 | if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) |
b34976b6 | 3003 | return FALSE; |
252b5132 | 3004 | break; |
9a5aca8c | 3005 | |
252b5132 RH |
3006 | /* This relocation describes which C++ vtable entries are actually |
3007 | used. Record for later use during GC. */ | |
3008 | case R_ARM_GNU_VTENTRY: | |
c152c796 | 3009 | if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset)) |
b34976b6 | 3010 | return FALSE; |
252b5132 RH |
3011 | break; |
3012 | } | |
3013 | } | |
f21f3fe0 | 3014 | |
b34976b6 | 3015 | return TRUE; |
252b5132 RH |
3016 | } |
3017 | ||
b34976b6 | 3018 | static bfd_boolean |
0367ecfb | 3019 | is_arm_mapping_symbol_name (const char * name) |
252b5132 | 3020 | { |
0367ecfb NC |
3021 | return (name != NULL) |
3022 | && (name[0] == '$') | |
3023 | && ((name[1] == 'a') || (name[1] == 't') || (name[1] == 'd')) | |
3024 | && (name[2] == 0); | |
3025 | } | |
f21f3fe0 | 3026 | |
0367ecfb NC |
3027 | /* This is a copy of elf_find_function() from elf.c except that |
3028 | ARM mapping symbols are ignored when looking for function names | |
3029 | and STT_ARM_TFUNC is considered to a function type. */ | |
252b5132 | 3030 | |
0367ecfb NC |
3031 | static bfd_boolean |
3032 | arm_elf_find_function (bfd * abfd ATTRIBUTE_UNUSED, | |
3033 | asection * section, | |
3034 | asymbol ** symbols, | |
3035 | bfd_vma offset, | |
3036 | const char ** filename_ptr, | |
3037 | const char ** functionname_ptr) | |
3038 | { | |
3039 | const char * filename = NULL; | |
3040 | asymbol * func = NULL; | |
3041 | bfd_vma low_func = 0; | |
3042 | asymbol ** p; | |
252b5132 RH |
3043 | |
3044 | for (p = symbols; *p != NULL; p++) | |
3045 | { | |
3046 | elf_symbol_type *q; | |
3047 | ||
3048 | q = (elf_symbol_type *) *p; | |
3049 | ||
3050 | if (bfd_get_section (&q->symbol) != section) | |
3051 | continue; | |
3052 | ||
3053 | switch (ELF_ST_TYPE (q->internal_elf_sym.st_info)) | |
3054 | { | |
3055 | default: | |
3056 | break; | |
3057 | case STT_FILE: | |
3058 | filename = bfd_asymbol_name (&q->symbol); | |
3059 | break; | |
252b5132 RH |
3060 | case STT_FUNC: |
3061 | case STT_ARM_TFUNC: | |
0367ecfb NC |
3062 | /* Skip $a and $t symbols. */ |
3063 | if ((q->symbol.flags & BSF_LOCAL) | |
3064 | && is_arm_mapping_symbol_name (q->symbol.name)) | |
3065 | continue; | |
3066 | /* Fall through. */ | |
3067 | case STT_NOTYPE: | |
252b5132 RH |
3068 | if (q->symbol.section == section |
3069 | && q->symbol.value >= low_func | |
3070 | && q->symbol.value <= offset) | |
3071 | { | |
3072 | func = (asymbol *) q; | |
3073 | low_func = q->symbol.value; | |
3074 | } | |
3075 | break; | |
3076 | } | |
3077 | } | |
3078 | ||
3079 | if (func == NULL) | |
b34976b6 | 3080 | return FALSE; |
252b5132 | 3081 | |
0367ecfb NC |
3082 | if (filename_ptr) |
3083 | *filename_ptr = filename; | |
3084 | if (functionname_ptr) | |
3085 | *functionname_ptr = bfd_asymbol_name (func); | |
3086 | ||
3087 | return TRUE; | |
3088 | } | |
3089 | ||
3090 | ||
3091 | /* Find the nearest line to a particular section and offset, for error | |
3092 | reporting. This code is a duplicate of the code in elf.c, except | |
3093 | that it uses arm_elf_find_function. */ | |
3094 | ||
3095 | static bfd_boolean | |
3096 | elf32_arm_find_nearest_line (bfd * abfd, | |
3097 | asection * section, | |
3098 | asymbol ** symbols, | |
3099 | bfd_vma offset, | |
3100 | const char ** filename_ptr, | |
3101 | const char ** functionname_ptr, | |
3102 | unsigned int * line_ptr) | |
3103 | { | |
3104 | bfd_boolean found = FALSE; | |
3105 | ||
3106 | /* We skip _bfd_dwarf1_find_nearest_line since no known ARM toolchain uses it. */ | |
3107 | ||
3108 | if (_bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset, | |
3109 | filename_ptr, functionname_ptr, | |
3110 | line_ptr, 0, | |
3111 | & elf_tdata (abfd)->dwarf2_find_line_info)) | |
3112 | { | |
3113 | if (!*functionname_ptr) | |
3114 | arm_elf_find_function (abfd, section, symbols, offset, | |
3115 | *filename_ptr ? NULL : filename_ptr, | |
3116 | functionname_ptr); | |
f21f3fe0 | 3117 | |
0367ecfb NC |
3118 | return TRUE; |
3119 | } | |
3120 | ||
3121 | if (! _bfd_stab_section_find_nearest_line (abfd, symbols, section, offset, | |
3122 | & found, filename_ptr, | |
3123 | functionname_ptr, line_ptr, | |
3124 | & elf_tdata (abfd)->line_info)) | |
3125 | return FALSE; | |
3126 | ||
3127 | if (found && (*functionname_ptr || *line_ptr)) | |
3128 | return TRUE; | |
3129 | ||
3130 | if (symbols == NULL) | |
3131 | return FALSE; | |
3132 | ||
3133 | if (! arm_elf_find_function (abfd, section, symbols, offset, | |
3134 | filename_ptr, functionname_ptr)) | |
3135 | return FALSE; | |
3136 | ||
3137 | *line_ptr = 0; | |
b34976b6 | 3138 | return TRUE; |
252b5132 RH |
3139 | } |
3140 | ||
3141 | /* Adjust a symbol defined by a dynamic object and referenced by a | |
3142 | regular object. The current definition is in some section of the | |
3143 | dynamic object, but we're not including those sections. We have to | |
3144 | change the definition to something the rest of the link can | |
3145 | understand. */ | |
3146 | ||
b34976b6 | 3147 | static bfd_boolean |
57e8b36a NC |
3148 | elf32_arm_adjust_dynamic_symbol (struct bfd_link_info * info, |
3149 | struct elf_link_hash_entry * h) | |
252b5132 RH |
3150 | { |
3151 | bfd * dynobj; | |
3152 | asection * s; | |
3153 | unsigned int power_of_two; | |
3154 | ||
3155 | dynobj = elf_hash_table (info)->dynobj; | |
3156 | ||
3157 | /* Make sure we know what is going on here. */ | |
3158 | BFD_ASSERT (dynobj != NULL | |
3159 | && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) | |
3160 | || h->weakdef != NULL | |
3161 | || ((h->elf_link_hash_flags | |
3162 | & ELF_LINK_HASH_DEF_DYNAMIC) != 0 | |
3163 | && (h->elf_link_hash_flags | |
3164 | & ELF_LINK_HASH_REF_REGULAR) != 0 | |
3165 | && (h->elf_link_hash_flags | |
3166 | & ELF_LINK_HASH_DEF_REGULAR) == 0))); | |
3167 | ||
3168 | /* If this is a function, put it in the procedure linkage table. We | |
3169 | will fill in the contents of the procedure linkage table later, | |
3170 | when we know the address of the .got section. */ | |
24a1ba0f | 3171 | if (h->type == STT_FUNC |
252b5132 RH |
3172 | || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0) |
3173 | { | |
5e681ec4 PB |
3174 | if (h->plt.refcount <= 0 |
3175 | || SYMBOL_CALLS_LOCAL (info, h) | |
3176 | || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT | |
3177 | && h->root.type == bfd_link_hash_undefweak)) | |
252b5132 RH |
3178 | { |
3179 | /* This case can occur if we saw a PLT32 reloc in an input | |
5e681ec4 PB |
3180 | file, but the symbol was never referred to by a dynamic |
3181 | object, or if all references were garbage collected. In | |
3182 | such a case, we don't actually need to build a procedure | |
3183 | linkage table, and we can just do a PC24 reloc instead. */ | |
3184 | h->plt.offset = (bfd_vma) -1; | |
9d7404b7 | 3185 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; |
252b5132 RH |
3186 | } |
3187 | ||
b34976b6 | 3188 | return TRUE; |
252b5132 | 3189 | } |
5e681ec4 PB |
3190 | else |
3191 | /* It's possible that we incorrectly decided a .plt reloc was | |
3192 | needed for an R_ARM_PC24 reloc to a non-function sym in | |
3193 | check_relocs. We can't decide accurately between function and | |
3194 | non-function syms in check-relocs; Objects loaded later in | |
3195 | the link may change h->type. So fix it now. */ | |
3196 | h->plt.offset = (bfd_vma) -1; | |
252b5132 RH |
3197 | |
3198 | /* If this is a weak symbol, and there is a real definition, the | |
3199 | processor independent code will have arranged for us to see the | |
3200 | real definition first, and we can just use the same value. */ | |
3201 | if (h->weakdef != NULL) | |
3202 | { | |
3203 | BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined | |
3204 | || h->weakdef->root.type == bfd_link_hash_defweak); | |
3205 | h->root.u.def.section = h->weakdef->root.u.def.section; | |
3206 | h->root.u.def.value = h->weakdef->root.u.def.value; | |
b34976b6 | 3207 | return TRUE; |
252b5132 RH |
3208 | } |
3209 | ||
3210 | /* This is a reference to a symbol defined by a dynamic object which | |
3211 | is not a function. */ | |
3212 | ||
3213 | /* If we are creating a shared library, we must presume that the | |
3214 | only references to the symbol are via the global offset table. | |
3215 | For such cases we need not do anything here; the relocations will | |
3216 | be handled correctly by relocate_section. */ | |
3217 | if (info->shared) | |
b34976b6 | 3218 | return TRUE; |
252b5132 RH |
3219 | |
3220 | /* We must allocate the symbol in our .dynbss section, which will | |
3221 | become part of the .bss section of the executable. There will be | |
3222 | an entry for this symbol in the .dynsym section. The dynamic | |
3223 | object will contain position independent code, so all references | |
3224 | from the dynamic object to this symbol will go through the global | |
3225 | offset table. The dynamic linker will use the .dynsym entry to | |
3226 | determine the address it must put in the global offset table, so | |
3227 | both the dynamic object and the regular object will refer to the | |
3228 | same memory location for the variable. */ | |
252b5132 RH |
3229 | s = bfd_get_section_by_name (dynobj, ".dynbss"); |
3230 | BFD_ASSERT (s != NULL); | |
3231 | ||
3232 | /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to | |
3233 | copy the initial value out of the dynamic object and into the | |
3234 | runtime process image. We need to remember the offset into the | |
3235 | .rel.bss section we are going to use. */ | |
3236 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0) | |
3237 | { | |
3238 | asection *srel; | |
3239 | ||
3240 | srel = bfd_get_section_by_name (dynobj, ".rel.bss"); | |
3241 | BFD_ASSERT (srel != NULL); | |
eea6121a | 3242 | srel->size += sizeof (Elf32_External_Rel); |
252b5132 RH |
3243 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY; |
3244 | } | |
3245 | ||
3246 | /* We need to figure out the alignment required for this symbol. I | |
3247 | have no idea how ELF linkers handle this. */ | |
3248 | power_of_two = bfd_log2 (h->size); | |
3249 | if (power_of_two > 3) | |
3250 | power_of_two = 3; | |
3251 | ||
3252 | /* Apply the required alignment. */ | |
eea6121a | 3253 | s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two)); |
252b5132 RH |
3254 | if (power_of_two > bfd_get_section_alignment (dynobj, s)) |
3255 | { | |
3256 | if (! bfd_set_section_alignment (dynobj, s, power_of_two)) | |
b34976b6 | 3257 | return FALSE; |
252b5132 RH |
3258 | } |
3259 | ||
3260 | /* Define the symbol as being at this point in the section. */ | |
3261 | h->root.u.def.section = s; | |
eea6121a | 3262 | h->root.u.def.value = s->size; |
252b5132 RH |
3263 | |
3264 | /* Increment the section size to make room for the symbol. */ | |
eea6121a | 3265 | s->size += h->size; |
252b5132 | 3266 | |
b34976b6 | 3267 | return TRUE; |
252b5132 RH |
3268 | } |
3269 | ||
5e681ec4 PB |
3270 | /* Allocate space in .plt, .got and associated reloc sections for |
3271 | dynamic relocs. */ | |
3272 | ||
3273 | static bfd_boolean | |
57e8b36a | 3274 | allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf) |
5e681ec4 PB |
3275 | { |
3276 | struct bfd_link_info *info; | |
3277 | struct elf32_arm_link_hash_table *htab; | |
3278 | struct elf32_arm_link_hash_entry *eh; | |
3279 | struct elf32_arm_relocs_copied *p; | |
3280 | ||
3281 | if (h->root.type == bfd_link_hash_indirect) | |
3282 | return TRUE; | |
3283 | ||
3284 | if (h->root.type == bfd_link_hash_warning) | |
3285 | /* When warning symbols are created, they **replace** the "real" | |
3286 | entry in the hash table, thus we never get to see the real | |
3287 | symbol in a hash traversal. So look at it now. */ | |
3288 | h = (struct elf_link_hash_entry *) h->root.u.i.link; | |
3289 | ||
3290 | info = (struct bfd_link_info *) inf; | |
3291 | htab = elf32_arm_hash_table (info); | |
3292 | ||
3293 | if (htab->root.dynamic_sections_created | |
3294 | && h->plt.refcount > 0) | |
3295 | { | |
3296 | /* Make sure this symbol is output as a dynamic symbol. | |
3297 | Undefined weak syms won't yet be marked as dynamic. */ | |
3298 | if (h->dynindx == -1 | |
3299 | && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) | |
3300 | { | |
c152c796 | 3301 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
5e681ec4 PB |
3302 | return FALSE; |
3303 | } | |
3304 | ||
3305 | if (info->shared | |
7359ea65 | 3306 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h)) |
5e681ec4 PB |
3307 | { |
3308 | asection *s = htab->splt; | |
3309 | ||
3310 | /* If this is the first .plt entry, make room for the special | |
3311 | first entry. */ | |
eea6121a | 3312 | if (s->size == 0) |
e5a52504 | 3313 | s->size += htab->plt_header_size; |
5e681ec4 | 3314 | |
eea6121a | 3315 | h->plt.offset = s->size; |
5e681ec4 PB |
3316 | |
3317 | /* If this symbol is not defined in a regular file, and we are | |
3318 | not generating a shared library, then set the symbol to this | |
3319 | location in the .plt. This is required to make function | |
3320 | pointers compare as equal between the normal executable and | |
3321 | the shared library. */ | |
3322 | if (! info->shared | |
3323 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) | |
3324 | { | |
3325 | h->root.u.def.section = s; | |
3326 | h->root.u.def.value = h->plt.offset; | |
3327 | } | |
3328 | ||
3329 | /* Make room for this entry. */ | |
e5a52504 | 3330 | s->size += htab->plt_entry_size; |
5e681ec4 | 3331 | |
e5a52504 MM |
3332 | if (!htab->symbian_p) |
3333 | /* We also need to make an entry in the .got.plt section, which | |
3334 | will be placed in the .got section by the linker script. */ | |
3335 | htab->sgotplt->size += 4; | |
5e681ec4 PB |
3336 | |
3337 | /* We also need to make an entry in the .rel.plt section. */ | |
eea6121a | 3338 | htab->srelplt->size += sizeof (Elf32_External_Rel); |
5e681ec4 PB |
3339 | } |
3340 | else | |
3341 | { | |
3342 | h->plt.offset = (bfd_vma) -1; | |
3343 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; | |
3344 | } | |
3345 | } | |
3346 | else | |
3347 | { | |
3348 | h->plt.offset = (bfd_vma) -1; | |
3349 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; | |
3350 | } | |
3351 | ||
3352 | if (h->got.refcount > 0) | |
3353 | { | |
3354 | asection *s; | |
3355 | bfd_boolean dyn; | |
3356 | ||
3357 | /* Make sure this symbol is output as a dynamic symbol. | |
3358 | Undefined weak syms won't yet be marked as dynamic. */ | |
3359 | if (h->dynindx == -1 | |
3360 | && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) | |
3361 | { | |
c152c796 | 3362 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
5e681ec4 PB |
3363 | return FALSE; |
3364 | } | |
3365 | ||
e5a52504 MM |
3366 | if (!htab->symbian_p) |
3367 | { | |
3368 | s = htab->sgot; | |
3369 | h->got.offset = s->size; | |
3370 | s->size += 4; | |
3371 | dyn = htab->root.dynamic_sections_created; | |
3372 | if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | |
3373 | || h->root.type != bfd_link_hash_undefweak) | |
3374 | && (info->shared | |
3375 | || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h))) | |
3376 | htab->srelgot->size += sizeof (Elf32_External_Rel); | |
3377 | } | |
5e681ec4 PB |
3378 | } |
3379 | else | |
3380 | h->got.offset = (bfd_vma) -1; | |
3381 | ||
3382 | eh = (struct elf32_arm_link_hash_entry *) h; | |
3383 | if (eh->relocs_copied == NULL) | |
3384 | return TRUE; | |
3385 | ||
3386 | /* In the shared -Bsymbolic case, discard space allocated for | |
3387 | dynamic pc-relative relocs against symbols which turn out to be | |
3388 | defined in regular objects. For the normal shared case, discard | |
3389 | space for pc-relative relocs that have become local due to symbol | |
3390 | visibility changes. */ | |
3391 | ||
3392 | if (info->shared) | |
3393 | { | |
7359ea65 DJ |
3394 | /* Discard relocs on undefined weak syms with non-default |
3395 | visibility. */ | |
5e681ec4 PB |
3396 | if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT |
3397 | && h->root.type == bfd_link_hash_undefweak) | |
3398 | eh->relocs_copied = NULL; | |
3399 | } | |
3400 | else | |
3401 | { | |
3402 | /* For the non-shared case, discard space for relocs against | |
3403 | symbols which turn out to need copy relocs or are not | |
3404 | dynamic. */ | |
3405 | ||
3406 | if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0 | |
3407 | && (((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0 | |
3408 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) | |
3409 | || (htab->root.dynamic_sections_created | |
3410 | && (h->root.type == bfd_link_hash_undefweak | |
3411 | || h->root.type == bfd_link_hash_undefined)))) | |
3412 | { | |
3413 | /* Make sure this symbol is output as a dynamic symbol. | |
3414 | Undefined weak syms won't yet be marked as dynamic. */ | |
3415 | if (h->dynindx == -1 | |
3416 | && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) | |
3417 | { | |
c152c796 | 3418 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
5e681ec4 PB |
3419 | return FALSE; |
3420 | } | |
3421 | ||
3422 | /* If that succeeded, we know we'll be keeping all the | |
3423 | relocs. */ | |
3424 | if (h->dynindx != -1) | |
3425 | goto keep; | |
3426 | } | |
3427 | ||
3428 | eh->relocs_copied = NULL; | |
3429 | ||
3430 | keep: ; | |
3431 | } | |
3432 | ||
3433 | /* Finally, allocate space. */ | |
3434 | for (p = eh->relocs_copied; p != NULL; p = p->next) | |
3435 | { | |
3436 | asection *sreloc = elf_section_data (p->section)->sreloc; | |
eea6121a | 3437 | sreloc->size += p->count * sizeof (Elf32_External_Rel); |
5e681ec4 PB |
3438 | } |
3439 | ||
3440 | return TRUE; | |
3441 | } | |
3442 | ||
252b5132 RH |
3443 | /* Set the sizes of the dynamic sections. */ |
3444 | ||
b34976b6 | 3445 | static bfd_boolean |
57e8b36a NC |
3446 | elf32_arm_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED, |
3447 | struct bfd_link_info * info) | |
252b5132 RH |
3448 | { |
3449 | bfd * dynobj; | |
3450 | asection * s; | |
b34976b6 AM |
3451 | bfd_boolean plt; |
3452 | bfd_boolean relocs; | |
5e681ec4 PB |
3453 | bfd *ibfd; |
3454 | struct elf32_arm_link_hash_table *htab; | |
252b5132 | 3455 | |
5e681ec4 | 3456 | htab = elf32_arm_hash_table (info); |
252b5132 RH |
3457 | dynobj = elf_hash_table (info)->dynobj; |
3458 | BFD_ASSERT (dynobj != NULL); | |
3459 | ||
3460 | if (elf_hash_table (info)->dynamic_sections_created) | |
3461 | { | |
3462 | /* Set the contents of the .interp section to the interpreter. */ | |
893c4fe2 | 3463 | if (info->executable) |
252b5132 RH |
3464 | { |
3465 | s = bfd_get_section_by_name (dynobj, ".interp"); | |
3466 | BFD_ASSERT (s != NULL); | |
eea6121a | 3467 | s->size = sizeof ELF_DYNAMIC_INTERPRETER; |
252b5132 RH |
3468 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; |
3469 | } | |
3470 | } | |
5e681ec4 PB |
3471 | |
3472 | /* Set up .got offsets for local syms, and space for local dynamic | |
3473 | relocs. */ | |
3474 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) | |
252b5132 | 3475 | { |
5e681ec4 PB |
3476 | bfd_signed_vma *local_got; |
3477 | bfd_signed_vma *end_local_got; | |
3478 | char *local_tls_type; | |
3479 | bfd_size_type locsymcount; | |
3480 | Elf_Internal_Shdr *symtab_hdr; | |
3481 | asection *srel; | |
3482 | ||
3483 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour) | |
3484 | continue; | |
3485 | ||
3486 | for (s = ibfd->sections; s != NULL; s = s->next) | |
3487 | { | |
3488 | struct elf32_arm_relocs_copied *p; | |
3489 | ||
3490 | for (p = *((struct elf32_arm_relocs_copied **) | |
3491 | &elf_section_data (s)->local_dynrel); | |
3492 | p != NULL; | |
3493 | p = p->next) | |
3494 | { | |
3495 | if (!bfd_is_abs_section (p->section) | |
3496 | && bfd_is_abs_section (p->section->output_section)) | |
3497 | { | |
3498 | /* Input section has been discarded, either because | |
3499 | it is a copy of a linkonce section or due to | |
3500 | linker script /DISCARD/, so we'll be discarding | |
3501 | the relocs too. */ | |
3502 | } | |
3503 | else if (p->count != 0) | |
3504 | { | |
3505 | srel = elf_section_data (p->section)->sreloc; | |
eea6121a | 3506 | srel->size += p->count * sizeof (Elf32_External_Rel); |
5e681ec4 PB |
3507 | if ((p->section->output_section->flags & SEC_READONLY) != 0) |
3508 | info->flags |= DF_TEXTREL; | |
3509 | } | |
3510 | } | |
3511 | } | |
3512 | ||
3513 | local_got = elf_local_got_refcounts (ibfd); | |
3514 | if (!local_got) | |
3515 | continue; | |
3516 | ||
3517 | symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; | |
3518 | locsymcount = symtab_hdr->sh_info; | |
3519 | end_local_got = local_got + locsymcount; | |
3520 | s = htab->sgot; | |
3521 | srel = htab->srelgot; | |
3522 | for (; local_got < end_local_got; ++local_got, ++local_tls_type) | |
3523 | { | |
3524 | if (*local_got > 0) | |
3525 | { | |
eea6121a AM |
3526 | *local_got = s->size; |
3527 | s->size += 4; | |
5e681ec4 | 3528 | if (info->shared) |
eea6121a | 3529 | srel->size += sizeof (Elf32_External_Rel); |
5e681ec4 PB |
3530 | } |
3531 | else | |
3532 | *local_got = (bfd_vma) -1; | |
3533 | } | |
252b5132 RH |
3534 | } |
3535 | ||
5e681ec4 PB |
3536 | /* Allocate global sym .plt and .got entries, and space for global |
3537 | sym dynamic relocs. */ | |
57e8b36a | 3538 | elf_link_hash_traverse (& htab->root, allocate_dynrelocs, info); |
252b5132 RH |
3539 | |
3540 | /* The check_relocs and adjust_dynamic_symbol entry points have | |
3541 | determined the sizes of the various dynamic sections. Allocate | |
3542 | memory for them. */ | |
b34976b6 AM |
3543 | plt = FALSE; |
3544 | relocs = FALSE; | |
252b5132 RH |
3545 | for (s = dynobj->sections; s != NULL; s = s->next) |
3546 | { | |
3547 | const char * name; | |
b34976b6 | 3548 | bfd_boolean strip; |
252b5132 RH |
3549 | |
3550 | if ((s->flags & SEC_LINKER_CREATED) == 0) | |
3551 | continue; | |
3552 | ||
3553 | /* It's OK to base decisions on the section name, because none | |
3554 | of the dynobj section names depend upon the input files. */ | |
3555 | name = bfd_get_section_name (dynobj, s); | |
3556 | ||
b34976b6 | 3557 | strip = FALSE; |
252b5132 | 3558 | |
24a1ba0f | 3559 | if (strcmp (name, ".plt") == 0) |
252b5132 | 3560 | { |
eea6121a | 3561 | if (s->size == 0) |
252b5132 RH |
3562 | { |
3563 | /* Strip this section if we don't need it; see the | |
3564 | comment below. */ | |
b34976b6 | 3565 | strip = TRUE; |
252b5132 RH |
3566 | } |
3567 | else | |
3568 | { | |
3569 | /* Remember whether there is a PLT. */ | |
b34976b6 | 3570 | plt = TRUE; |
252b5132 RH |
3571 | } |
3572 | } | |
3573 | else if (strncmp (name, ".rel", 4) == 0) | |
3574 | { | |
eea6121a | 3575 | if (s->size == 0) |
252b5132 RH |
3576 | { |
3577 | /* If we don't need this section, strip it from the | |
3578 | output file. This is mostly to handle .rel.bss and | |
3579 | .rel.plt. We must create both sections in | |
3580 | create_dynamic_sections, because they must be created | |
3581 | before the linker maps input sections to output | |
3582 | sections. The linker does that before | |
3583 | adjust_dynamic_symbol is called, and it is that | |
3584 | function which decides whether anything needs to go | |
3585 | into these sections. */ | |
b34976b6 | 3586 | strip = TRUE; |
252b5132 RH |
3587 | } |
3588 | else | |
3589 | { | |
252b5132 RH |
3590 | /* Remember whether there are any reloc sections other |
3591 | than .rel.plt. */ | |
3592 | if (strcmp (name, ".rel.plt") != 0) | |
b34976b6 | 3593 | relocs = TRUE; |
252b5132 RH |
3594 | |
3595 | /* We use the reloc_count field as a counter if we need | |
3596 | to copy relocs into the output file. */ | |
3597 | s->reloc_count = 0; | |
3598 | } | |
3599 | } | |
3600 | else if (strncmp (name, ".got", 4) != 0) | |
3601 | { | |
3602 | /* It's not one of our sections, so don't allocate space. */ | |
3603 | continue; | |
3604 | } | |
3605 | ||
3606 | if (strip) | |
3607 | { | |
52585bb8 | 3608 | _bfd_strip_section_from_output (info, s); |
252b5132 RH |
3609 | continue; |
3610 | } | |
3611 | ||
3612 | /* Allocate memory for the section contents. */ | |
eea6121a AM |
3613 | s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size); |
3614 | if (s->contents == NULL && s->size != 0) | |
b34976b6 | 3615 | return FALSE; |
252b5132 RH |
3616 | } |
3617 | ||
3618 | if (elf_hash_table (info)->dynamic_sections_created) | |
3619 | { | |
3620 | /* Add some entries to the .dynamic section. We fill in the | |
3621 | values later, in elf32_arm_finish_dynamic_sections, but we | |
3622 | must add the entries now so that we get the correct size for | |
3623 | the .dynamic section. The DT_DEBUG entry is filled in by the | |
3624 | dynamic linker and used by the debugger. */ | |
dc810e39 | 3625 | #define add_dynamic_entry(TAG, VAL) \ |
5a580b3a | 3626 | _bfd_elf_add_dynamic_entry (info, TAG, VAL) |
dc810e39 AM |
3627 | |
3628 | if (!info->shared) | |
252b5132 | 3629 | { |
dc810e39 | 3630 | if (!add_dynamic_entry (DT_DEBUG, 0)) |
b34976b6 | 3631 | return FALSE; |
252b5132 RH |
3632 | } |
3633 | ||
3634 | if (plt) | |
3635 | { | |
dc810e39 AM |
3636 | if ( !add_dynamic_entry (DT_PLTGOT, 0) |
3637 | || !add_dynamic_entry (DT_PLTRELSZ, 0) | |
3638 | || !add_dynamic_entry (DT_PLTREL, DT_REL) | |
3639 | || !add_dynamic_entry (DT_JMPREL, 0)) | |
b34976b6 | 3640 | return FALSE; |
252b5132 RH |
3641 | } |
3642 | ||
3643 | if (relocs) | |
3644 | { | |
dc810e39 AM |
3645 | if ( !add_dynamic_entry (DT_REL, 0) |
3646 | || !add_dynamic_entry (DT_RELSZ, 0) | |
3647 | || !add_dynamic_entry (DT_RELENT, sizeof (Elf32_External_Rel))) | |
b34976b6 | 3648 | return FALSE; |
252b5132 RH |
3649 | } |
3650 | ||
99e4ae17 | 3651 | if ((info->flags & DF_TEXTREL) != 0) |
252b5132 | 3652 | { |
dc810e39 | 3653 | if (!add_dynamic_entry (DT_TEXTREL, 0)) |
b34976b6 | 3654 | return FALSE; |
d6cf2879 | 3655 | info->flags |= DF_TEXTREL; |
252b5132 RH |
3656 | } |
3657 | } | |
dc810e39 | 3658 | #undef add_synamic_entry |
252b5132 | 3659 | |
b34976b6 | 3660 | return TRUE; |
252b5132 RH |
3661 | } |
3662 | ||
252b5132 RH |
3663 | /* Finish up dynamic symbol handling. We set the contents of various |
3664 | dynamic sections here. */ | |
3665 | ||
b34976b6 | 3666 | static bfd_boolean |
57e8b36a NC |
3667 | elf32_arm_finish_dynamic_symbol (bfd * output_bfd, struct bfd_link_info * info, |
3668 | struct elf_link_hash_entry * h, Elf_Internal_Sym * sym) | |
252b5132 RH |
3669 | { |
3670 | bfd * dynobj; | |
e5a52504 | 3671 | struct elf32_arm_link_hash_table *htab; |
252b5132 RH |
3672 | |
3673 | dynobj = elf_hash_table (info)->dynobj; | |
e5a52504 | 3674 | htab = elf32_arm_hash_table (info); |
252b5132 RH |
3675 | |
3676 | if (h->plt.offset != (bfd_vma) -1) | |
3677 | { | |
3678 | asection * splt; | |
252b5132 | 3679 | asection * srel; |
e5a52504 | 3680 | bfd_byte *loc; |
24a1ba0f | 3681 | bfd_vma plt_index; |
947216bf | 3682 | Elf_Internal_Rela rel; |
252b5132 RH |
3683 | |
3684 | /* This symbol has an entry in the procedure linkage table. Set | |
3685 | it up. */ | |
3686 | ||
3687 | BFD_ASSERT (h->dynindx != -1); | |
3688 | ||
3689 | splt = bfd_get_section_by_name (dynobj, ".plt"); | |
252b5132 | 3690 | srel = bfd_get_section_by_name (dynobj, ".rel.plt"); |
e5a52504 | 3691 | BFD_ASSERT (splt != NULL && srel != NULL); |
252b5132 | 3692 | |
24a1ba0f NC |
3693 | /* Get the index in the procedure linkage table which |
3694 | corresponds to this symbol. This is the index of this symbol | |
3695 | in all the symbols for which we are making plt entries. The | |
3696 | first entry in the procedure linkage table is reserved. */ | |
e5a52504 MM |
3697 | plt_index = ((h->plt.offset - htab->plt_header_size) |
3698 | / htab->plt_entry_size); | |
252b5132 | 3699 | |
e5a52504 MM |
3700 | /* Fill in the entry in the procedure linkage table. */ |
3701 | if (htab->symbian_p) | |
3702 | { | |
3703 | unsigned i; | |
3704 | for (i = 0; i < htab->plt_entry_size / 4; ++i) | |
3705 | bfd_put_32 (output_bfd, | |
3706 | elf32_arm_symbian_plt_entry[i], | |
3707 | splt->contents + h->plt.offset + 4 * i); | |
3708 | ||
3709 | /* Fill in the entry in the .rel.plt section. */ | |
3710 | rel.r_offset = (splt->output_offset | |
3711 | + h->plt.offset + 4 * (i - 1)); | |
3712 | rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT); | |
3713 | } | |
3714 | else | |
3715 | { | |
3716 | bfd_vma got_offset; | |
3717 | bfd_vma got_displacement; | |
3718 | asection * sgot; | |
3719 | ||
3720 | sgot = bfd_get_section_by_name (dynobj, ".got.plt"); | |
3721 | BFD_ASSERT (sgot != NULL); | |
3722 | ||
3723 | /* Get the offset into the .got table of the entry that | |
3724 | corresponds to this function. Each .got entry is 4 bytes. | |
3725 | The first three are reserved. */ | |
3726 | got_offset = (plt_index + 3) * 4; | |
3727 | ||
3728 | /* Calculate the displacement between the PLT slot and the | |
3729 | entry in the GOT. */ | |
3730 | got_displacement = (sgot->output_section->vma | |
3731 | + sgot->output_offset | |
3732 | + got_offset | |
3733 | - splt->output_section->vma | |
3734 | - splt->output_offset | |
3735 | - h->plt.offset | |
3736 | - 8); | |
5e681ec4 | 3737 | |
e5a52504 | 3738 | BFD_ASSERT ((got_displacement & 0xf0000000) == 0); |
5e681ec4 | 3739 | |
e5a52504 MM |
3740 | bfd_put_32 (output_bfd, elf32_arm_plt_entry[0] | ((got_displacement & 0x0ff00000) >> 20), |
3741 | splt->contents + h->plt.offset + 0); | |
3742 | bfd_put_32 (output_bfd, elf32_arm_plt_entry[1] | ((got_displacement & 0x000ff000) >> 12), | |
3743 | splt->contents + h->plt.offset + 4); | |
3744 | bfd_put_32 (output_bfd, elf32_arm_plt_entry[2] | (got_displacement & 0x00000fff), | |
3745 | splt->contents + h->plt.offset + 8); | |
5e681ec4 | 3746 | #ifdef FOUR_WORD_PLT |
e5a52504 MM |
3747 | bfd_put_32 (output_bfd, elf32_arm_plt_entry[3], |
3748 | splt->contents + h->plt.offset + 12); | |
5e681ec4 | 3749 | #endif |
252b5132 | 3750 | |
e5a52504 MM |
3751 | /* Fill in the entry in the global offset table. */ |
3752 | bfd_put_32 (output_bfd, | |
3753 | (splt->output_section->vma | |
3754 | + splt->output_offset), | |
3755 | sgot->contents + got_offset); | |
3756 | ||
3757 | /* Fill in the entry in the .rel.plt section. */ | |
3758 | rel.r_offset = (sgot->output_section->vma | |
3759 | + sgot->output_offset | |
3760 | + got_offset); | |
3761 | rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_JUMP_SLOT); | |
3762 | } | |
57e8b36a | 3763 | |
947216bf AM |
3764 | loc = srel->contents + plt_index * sizeof (Elf32_External_Rel); |
3765 | bfd_elf32_swap_reloc_out (output_bfd, &rel, loc); | |
252b5132 RH |
3766 | |
3767 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) | |
3768 | { | |
3769 | /* Mark the symbol as undefined, rather than as defined in | |
3770 | the .plt section. Leave the value alone. */ | |
3771 | sym->st_shndx = SHN_UNDEF; | |
d982ba73 PB |
3772 | /* If the symbol is weak, we do need to clear the value. |
3773 | Otherwise, the PLT entry would provide a definition for | |
3774 | the symbol even if the symbol wasn't defined anywhere, | |
3775 | and so the symbol would never be NULL. */ | |
3776 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR_NONWEAK) | |
3777 | == 0) | |
3778 | sym->st_value = 0; | |
252b5132 RH |
3779 | } |
3780 | } | |
3781 | ||
3782 | if (h->got.offset != (bfd_vma) -1) | |
3783 | { | |
3784 | asection * sgot; | |
3785 | asection * srel; | |
947216bf AM |
3786 | Elf_Internal_Rela rel; |
3787 | bfd_byte *loc; | |
252b5132 RH |
3788 | |
3789 | /* This symbol has an entry in the global offset table. Set it | |
3790 | up. */ | |
252b5132 RH |
3791 | sgot = bfd_get_section_by_name (dynobj, ".got"); |
3792 | srel = bfd_get_section_by_name (dynobj, ".rel.got"); | |
3793 | BFD_ASSERT (sgot != NULL && srel != NULL); | |
3794 | ||
3795 | rel.r_offset = (sgot->output_section->vma | |
3796 | + sgot->output_offset | |
dc810e39 | 3797 | + (h->got.offset &~ (bfd_vma) 1)); |
252b5132 | 3798 | |
5e681ec4 PB |
3799 | /* If this is a static link, or it is a -Bsymbolic link and the |
3800 | symbol is defined locally or was forced to be local because | |
3801 | of a version file, we just want to emit a RELATIVE reloc. | |
3802 | The entry in the global offset table will already have been | |
3803 | initialized in the relocate_section function. */ | |
252b5132 | 3804 | if (info->shared |
5e681ec4 PB |
3805 | && SYMBOL_REFERENCES_LOCAL (info, h)) |
3806 | { | |
3807 | BFD_ASSERT((h->got.offset & 1) != 0); | |
3808 | rel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE); | |
3809 | } | |
252b5132 RH |
3810 | else |
3811 | { | |
5e681ec4 | 3812 | BFD_ASSERT((h->got.offset & 1) == 0); |
252b5132 RH |
3813 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset); |
3814 | rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT); | |
3815 | } | |
3816 | ||
947216bf AM |
3817 | loc = srel->contents + srel->reloc_count++ * sizeof (Elf32_External_Rel); |
3818 | bfd_elf32_swap_reloc_out (output_bfd, &rel, loc); | |
252b5132 RH |
3819 | } |
3820 | ||
3821 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0) | |
3822 | { | |
3823 | asection * s; | |
947216bf AM |
3824 | Elf_Internal_Rela rel; |
3825 | bfd_byte *loc; | |
252b5132 RH |
3826 | |
3827 | /* This symbol needs a copy reloc. Set it up. */ | |
252b5132 RH |
3828 | BFD_ASSERT (h->dynindx != -1 |
3829 | && (h->root.type == bfd_link_hash_defined | |
3830 | || h->root.type == bfd_link_hash_defweak)); | |
3831 | ||
3832 | s = bfd_get_section_by_name (h->root.u.def.section->owner, | |
3833 | ".rel.bss"); | |
3834 | BFD_ASSERT (s != NULL); | |
3835 | ||
3836 | rel.r_offset = (h->root.u.def.value | |
3837 | + h->root.u.def.section->output_section->vma | |
3838 | + h->root.u.def.section->output_offset); | |
3839 | rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_COPY); | |
947216bf AM |
3840 | loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rel); |
3841 | bfd_elf32_swap_reloc_out (output_bfd, &rel, loc); | |
252b5132 RH |
3842 | } |
3843 | ||
3844 | /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */ | |
3845 | if (strcmp (h->root.root.string, "_DYNAMIC") == 0 | |
3846 | || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0) | |
3847 | sym->st_shndx = SHN_ABS; | |
3848 | ||
b34976b6 | 3849 | return TRUE; |
252b5132 RH |
3850 | } |
3851 | ||
3852 | /* Finish up the dynamic sections. */ | |
3853 | ||
b34976b6 | 3854 | static bfd_boolean |
57e8b36a | 3855 | elf32_arm_finish_dynamic_sections (bfd * output_bfd, struct bfd_link_info * info) |
252b5132 RH |
3856 | { |
3857 | bfd * dynobj; | |
3858 | asection * sgot; | |
3859 | asection * sdyn; | |
3860 | ||
3861 | dynobj = elf_hash_table (info)->dynobj; | |
3862 | ||
3863 | sgot = bfd_get_section_by_name (dynobj, ".got.plt"); | |
229fcec5 | 3864 | BFD_ASSERT (elf32_arm_hash_table (info)->symbian_p || sgot != NULL); |
252b5132 RH |
3865 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); |
3866 | ||
3867 | if (elf_hash_table (info)->dynamic_sections_created) | |
3868 | { | |
3869 | asection *splt; | |
3870 | Elf32_External_Dyn *dyncon, *dynconend; | |
229fcec5 | 3871 | struct elf32_arm_link_hash_table *htab; |
252b5132 | 3872 | |
229fcec5 | 3873 | htab = elf32_arm_hash_table (info); |
252b5132 | 3874 | splt = bfd_get_section_by_name (dynobj, ".plt"); |
24a1ba0f | 3875 | BFD_ASSERT (splt != NULL && sdyn != NULL); |
252b5132 RH |
3876 | |
3877 | dyncon = (Elf32_External_Dyn *) sdyn->contents; | |
eea6121a | 3878 | dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size); |
9b485d32 | 3879 | |
252b5132 RH |
3880 | for (; dyncon < dynconend; dyncon++) |
3881 | { | |
3882 | Elf_Internal_Dyn dyn; | |
3883 | const char * name; | |
3884 | asection * s; | |
3885 | ||
3886 | bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn); | |
3887 | ||
3888 | switch (dyn.d_tag) | |
3889 | { | |
229fcec5 MM |
3890 | unsigned int type; |
3891 | ||
252b5132 RH |
3892 | default: |
3893 | break; | |
3894 | ||
229fcec5 MM |
3895 | case DT_HASH: |
3896 | name = ".hash"; | |
3897 | goto get_vma_if_bpabi; | |
3898 | case DT_STRTAB: | |
3899 | name = ".dynstr"; | |
3900 | goto get_vma_if_bpabi; | |
3901 | case DT_SYMTAB: | |
3902 | name = ".dynsym"; | |
3903 | goto get_vma_if_bpabi; | |
3904 | ||
252b5132 RH |
3905 | case DT_PLTGOT: |
3906 | name = ".got"; | |
3907 | goto get_vma; | |
3908 | case DT_JMPREL: | |
3909 | name = ".rel.plt"; | |
3910 | get_vma: | |
3911 | s = bfd_get_section_by_name (output_bfd, name); | |
3912 | BFD_ASSERT (s != NULL); | |
229fcec5 MM |
3913 | if (!htab->symbian_p) |
3914 | dyn.d_un.d_ptr = s->vma; | |
3915 | else | |
3916 | /* In the BPABI, tags in the PT_DYNAMIC section point | |
3917 | at the file offset, not the memory address, for the | |
3918 | convenience of the post linker. */ | |
3919 | dyn.d_un.d_ptr = s->filepos; | |
252b5132 RH |
3920 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
3921 | break; | |
3922 | ||
229fcec5 MM |
3923 | get_vma_if_bpabi: |
3924 | if (htab->symbian_p) | |
3925 | goto get_vma; | |
3926 | break; | |
3927 | ||
252b5132 RH |
3928 | case DT_PLTRELSZ: |
3929 | s = bfd_get_section_by_name (output_bfd, ".rel.plt"); | |
3930 | BFD_ASSERT (s != NULL); | |
eea6121a | 3931 | dyn.d_un.d_val = s->size; |
252b5132 RH |
3932 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
3933 | break; | |
229fcec5 | 3934 | |
252b5132 | 3935 | case DT_RELSZ: |
229fcec5 MM |
3936 | if (!htab->symbian_p) |
3937 | { | |
3938 | /* My reading of the SVR4 ABI indicates that the | |
3939 | procedure linkage table relocs (DT_JMPREL) should be | |
3940 | included in the overall relocs (DT_REL). This is | |
3941 | what Solaris does. However, UnixWare can not handle | |
3942 | that case. Therefore, we override the DT_RELSZ entry | |
3943 | here to make it not include the JMPREL relocs. Since | |
3944 | the linker script arranges for .rel.plt to follow all | |
3945 | other relocation sections, we don't have to worry | |
3946 | about changing the DT_REL entry. */ | |
3947 | s = bfd_get_section_by_name (output_bfd, ".rel.plt"); | |
3948 | if (s != NULL) | |
3949 | dyn.d_un.d_val -= s->size; | |
3950 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); | |
3951 | break; | |
3952 | } | |
3953 | /* Fall through */ | |
3954 | ||
3955 | case DT_REL: | |
3956 | case DT_RELA: | |
3957 | case DT_RELASZ: | |
3958 | /* In the BPABI, the DT_REL tag must point at the file | |
3959 | offset, not the VMA, of the first relocation | |
3960 | section. So, we use code similar to that in | |
3961 | elflink.c, but do not check for SHF_ALLOC on the | |
3962 | relcoation section, since relocations sections are | |
3963 | never allocated under the BPABI. The comments above | |
3964 | about Unixware notwithstanding, we include all of the | |
3965 | relocations here. */ | |
3966 | if (htab->symbian_p) | |
3967 | { | |
3968 | unsigned int i; | |
3969 | type = ((dyn.d_tag == DT_REL || dyn.d_tag == DT_RELSZ) | |
3970 | ? SHT_REL : SHT_RELA); | |
3971 | dyn.d_un.d_val = 0; | |
3972 | for (i = 1; i < elf_numsections (output_bfd); i++) | |
3973 | { | |
3974 | Elf_Internal_Shdr *hdr | |
3975 | = elf_elfsections (output_bfd)[i]; | |
3976 | if (hdr->sh_type == type) | |
3977 | { | |
3978 | if (dyn.d_tag == DT_RELSZ | |
3979 | || dyn.d_tag == DT_RELASZ) | |
3980 | dyn.d_un.d_val += hdr->sh_size; | |
3981 | else if (dyn.d_un.d_val == 0 | |
3982 | || hdr->sh_offset < dyn.d_un.d_val) | |
3983 | dyn.d_un.d_val = hdr->sh_offset; | |
3984 | } | |
3985 | } | |
3986 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); | |
3987 | } | |
252b5132 | 3988 | break; |
88f7bcd5 NC |
3989 | |
3990 | /* Set the bottom bit of DT_INIT/FINI if the | |
3991 | corresponding function is Thumb. */ | |
3992 | case DT_INIT: | |
3993 | name = info->init_function; | |
3994 | goto get_sym; | |
3995 | case DT_FINI: | |
3996 | name = info->fini_function; | |
3997 | get_sym: | |
3998 | /* If it wasn't set by elf_bfd_final_link | |
4cc11e76 | 3999 | then there is nothing to adjust. */ |
88f7bcd5 NC |
4000 | if (dyn.d_un.d_val != 0) |
4001 | { | |
4002 | struct elf_link_hash_entry * eh; | |
4003 | ||
4004 | eh = elf_link_hash_lookup (elf_hash_table (info), name, | |
b34976b6 | 4005 | FALSE, FALSE, TRUE); |
88f7bcd5 NC |
4006 | if (eh != (struct elf_link_hash_entry *) NULL |
4007 | && ELF_ST_TYPE (eh->type) == STT_ARM_TFUNC) | |
4008 | { | |
4009 | dyn.d_un.d_val |= 1; | |
b34976b6 | 4010 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
88f7bcd5 NC |
4011 | } |
4012 | } | |
4013 | break; | |
252b5132 RH |
4014 | } |
4015 | } | |
4016 | ||
24a1ba0f | 4017 | /* Fill in the first entry in the procedure linkage table. */ |
e5a52504 | 4018 | if (splt->size > 0 && elf32_arm_hash_table (info)->plt_header_size) |
f7a74f8c | 4019 | { |
5e681ec4 PB |
4020 | bfd_vma got_displacement; |
4021 | ||
4022 | /* Calculate the displacement between the PLT slot and &GOT[0]. */ | |
4023 | got_displacement = (sgot->output_section->vma | |
4024 | + sgot->output_offset | |
4025 | - splt->output_section->vma | |
4026 | - splt->output_offset | |
4027 | - 16); | |
4028 | ||
f7a74f8c NC |
4029 | bfd_put_32 (output_bfd, elf32_arm_plt0_entry[0], splt->contents + 0); |
4030 | bfd_put_32 (output_bfd, elf32_arm_plt0_entry[1], splt->contents + 4); | |
4031 | bfd_put_32 (output_bfd, elf32_arm_plt0_entry[2], splt->contents + 8); | |
4032 | bfd_put_32 (output_bfd, elf32_arm_plt0_entry[3], splt->contents + 12); | |
5e681ec4 PB |
4033 | #ifdef FOUR_WORD_PLT |
4034 | /* The displacement value goes in the otherwise-unused last word of | |
4035 | the second entry. */ | |
4036 | bfd_put_32 (output_bfd, got_displacement, splt->contents + 28); | |
4037 | #else | |
4038 | bfd_put_32 (output_bfd, got_displacement, splt->contents + 16); | |
4039 | #endif | |
f7a74f8c | 4040 | } |
252b5132 RH |
4041 | |
4042 | /* UnixWare sets the entsize of .plt to 4, although that doesn't | |
4043 | really seem like the right value. */ | |
4044 | elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4; | |
4045 | } | |
4046 | ||
4047 | /* Fill in the first three entries in the global offset table. */ | |
229fcec5 | 4048 | if (sgot) |
252b5132 | 4049 | { |
229fcec5 MM |
4050 | if (sgot->size > 0) |
4051 | { | |
4052 | if (sdyn == NULL) | |
4053 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents); | |
4054 | else | |
4055 | bfd_put_32 (output_bfd, | |
4056 | sdyn->output_section->vma + sdyn->output_offset, | |
4057 | sgot->contents); | |
4058 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4); | |
4059 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8); | |
4060 | } | |
252b5132 | 4061 | |
229fcec5 MM |
4062 | elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4; |
4063 | } | |
252b5132 | 4064 | |
b34976b6 | 4065 | return TRUE; |
252b5132 RH |
4066 | } |
4067 | ||
ba96a88f | 4068 | static void |
57e8b36a | 4069 | elf32_arm_post_process_headers (bfd * abfd, struct bfd_link_info * link_info ATTRIBUTE_UNUSED) |
ba96a88f | 4070 | { |
9b485d32 | 4071 | Elf_Internal_Ehdr * i_ehdrp; /* ELF file header, internal form. */ |
e489d0ae | 4072 | struct elf32_arm_link_hash_table *globals; |
ba96a88f NC |
4073 | |
4074 | i_ehdrp = elf_elfheader (abfd); | |
4075 | ||
4076 | i_ehdrp->e_ident[EI_OSABI] = ARM_ELF_OS_ABI_VERSION; | |
4077 | i_ehdrp->e_ident[EI_ABIVERSION] = ARM_ELF_ABI_VERSION; | |
e489d0ae | 4078 | |
93204d3a PB |
4079 | if (link_info) |
4080 | { | |
4081 | globals = elf32_arm_hash_table (link_info); | |
4082 | if (globals->byteswap_code) | |
4083 | i_ehdrp->e_flags |= EF_ARM_BE8; | |
4084 | } | |
ba96a88f NC |
4085 | } |
4086 | ||
99e4ae17 | 4087 | static enum elf_reloc_type_class |
57e8b36a | 4088 | elf32_arm_reloc_type_class (const Elf_Internal_Rela *rela) |
99e4ae17 | 4089 | { |
f51e552e | 4090 | switch ((int) ELF32_R_TYPE (rela->r_info)) |
99e4ae17 AJ |
4091 | { |
4092 | case R_ARM_RELATIVE: | |
4093 | return reloc_class_relative; | |
4094 | case R_ARM_JUMP_SLOT: | |
4095 | return reloc_class_plt; | |
4096 | case R_ARM_COPY: | |
4097 | return reloc_class_copy; | |
4098 | default: | |
4099 | return reloc_class_normal; | |
4100 | } | |
4101 | } | |
4102 | ||
57e8b36a NC |
4103 | static bfd_boolean elf32_arm_section_flags (flagword *, const Elf_Internal_Shdr *); |
4104 | static void elf32_arm_final_write_processing (bfd *, bfd_boolean); | |
e16bb312 NC |
4105 | |
4106 | /* Set the right machine number for an Arm ELF file. */ | |
4107 | ||
4108 | static bfd_boolean | |
57e8b36a | 4109 | elf32_arm_section_flags (flagword *flags, const Elf_Internal_Shdr *hdr) |
e16bb312 NC |
4110 | { |
4111 | if (hdr->sh_type == SHT_NOTE) | |
4112 | *flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_SAME_CONTENTS; | |
4113 | ||
4114 | return TRUE; | |
4115 | } | |
4116 | ||
e489d0ae | 4117 | static void |
57e8b36a | 4118 | elf32_arm_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED) |
e16bb312 | 4119 | { |
5a6c6817 | 4120 | bfd_arm_update_notes (abfd, ARM_NOTE_SECTION); |
e16bb312 NC |
4121 | } |
4122 | ||
e489d0ae PB |
4123 | |
4124 | /* Called for each symbol. Builds a section map based on mapping symbols. | |
4125 | Does not alter any of the symbols. */ | |
4126 | ||
4127 | static bfd_boolean | |
4128 | elf32_arm_output_symbol_hook (struct bfd_link_info *info, | |
4129 | const char *name, | |
4130 | Elf_Internal_Sym *elfsym, | |
4131 | asection *input_sec, | |
4132 | struct elf_link_hash_entry *h ATTRIBUTE_UNUSED) | |
4133 | { | |
4134 | int mapcount; | |
4135 | elf32_arm_section_map *map; | |
4136 | struct elf32_arm_link_hash_table *globals; | |
4137 | ||
4138 | /* Only do this on final link. */ | |
4139 | if (info->relocatable) | |
4140 | return TRUE; | |
4141 | ||
4142 | /* Only build a map if we need to byteswap code. */ | |
4143 | globals = elf32_arm_hash_table (info); | |
4144 | if (!globals->byteswap_code) | |
4145 | return TRUE; | |
4146 | ||
4147 | /* We only want mapping symbols. */ | |
0367ecfb | 4148 | if (! is_arm_mapping_symbol_name (name)) |
e489d0ae PB |
4149 | return TRUE; |
4150 | ||
4151 | mapcount = ++(elf32_arm_section_data (input_sec)->mapcount); | |
4152 | map = elf32_arm_section_data (input_sec)->map; | |
4153 | /* TODO: This may be inefficient, but we probably don't usually have many | |
4154 | mapping symbols per section. */ | |
4155 | map = bfd_realloc (map, mapcount * sizeof (elf32_arm_section_map)); | |
4156 | elf32_arm_section_data (input_sec)->map = map; | |
57e8b36a | 4157 | |
e489d0ae PB |
4158 | map[mapcount - 1].vma = elfsym->st_value; |
4159 | map[mapcount - 1].type = name[1]; | |
4160 | return TRUE; | |
4161 | } | |
4162 | ||
4163 | ||
4164 | /* Allocate target specific section data. */ | |
4165 | ||
4166 | static bfd_boolean | |
4167 | elf32_arm_new_section_hook (bfd *abfd, asection *sec) | |
4168 | { | |
4169 | struct _arm_elf_section_data *sdata; | |
4170 | bfd_size_type amt = sizeof (*sdata); | |
4171 | ||
4172 | sdata = bfd_zalloc (abfd, amt); | |
4173 | if (sdata == NULL) | |
4174 | return FALSE; | |
4175 | sec->used_by_bfd = sdata; | |
4176 | ||
4177 | return _bfd_elf_new_section_hook (abfd, sec); | |
4178 | } | |
4179 | ||
4180 | ||
4181 | /* Used to order a list of mapping symbols by address. */ | |
4182 | ||
4183 | static int | |
4184 | elf32_arm_compare_mapping (const void * a, const void * b) | |
4185 | { | |
4186 | return ((const elf32_arm_section_map *) a)->vma | |
4187 | > ((const elf32_arm_section_map *) b)->vma; | |
4188 | } | |
4189 | ||
4190 | ||
4191 | /* Do code byteswapping. Return FALSE afterwards so that the section is | |
4192 | written out as normal. */ | |
4193 | ||
4194 | static bfd_boolean | |
4195 | elf32_arm_write_section (bfd *output_bfd ATTRIBUTE_UNUSED, asection *sec, | |
4196 | bfd_byte *contents) | |
4197 | { | |
4198 | int mapcount; | |
4199 | elf32_arm_section_map *map; | |
4200 | bfd_vma ptr; | |
4201 | bfd_vma end; | |
4202 | bfd_vma offset; | |
4203 | bfd_byte tmp; | |
4204 | int i; | |
57e8b36a | 4205 | |
e489d0ae PB |
4206 | mapcount = elf32_arm_section_data (sec)->mapcount; |
4207 | map = elf32_arm_section_data (sec)->map; | |
4208 | ||
4209 | if (mapcount == 0) | |
4210 | return FALSE; | |
4211 | ||
4212 | qsort (map, mapcount, sizeof (elf32_arm_section_map), | |
4213 | elf32_arm_compare_mapping); | |
4214 | ||
4215 | offset = sec->output_section->vma + sec->output_offset; | |
4216 | ptr = map[0].vma - offset; | |
4217 | for (i = 0; i < mapcount; i++) | |
4218 | { | |
4219 | if (i == mapcount - 1) | |
eea6121a | 4220 | end = sec->size; |
e489d0ae PB |
4221 | else |
4222 | end = map[i + 1].vma - offset; | |
57e8b36a | 4223 | |
e489d0ae PB |
4224 | switch (map[i].type) |
4225 | { | |
4226 | case 'a': | |
4227 | /* Byte swap code words. */ | |
4228 | while (ptr + 3 < end) | |
4229 | { | |
4230 | tmp = contents[ptr]; | |
4231 | contents[ptr] = contents[ptr + 3]; | |
4232 | contents[ptr + 3] = tmp; | |
4233 | tmp = contents[ptr + 1]; | |
4234 | contents[ptr + 1] = contents[ptr + 2]; | |
4235 | contents[ptr + 2] = tmp; | |
4236 | ptr += 4; | |
4237 | } | |
4238 | break; | |
4239 | ||
4240 | case 't': | |
4241 | /* Byte swap code halfwords. */ | |
4242 | while (ptr + 1 < end) | |
4243 | { | |
4244 | tmp = contents[ptr]; | |
4245 | contents[ptr] = contents[ptr + 1]; | |
4246 | contents[ptr + 1] = tmp; | |
4247 | ptr += 2; | |
4248 | } | |
4249 | break; | |
4250 | ||
4251 | case 'd': | |
4252 | /* Leave data alone. */ | |
4253 | break; | |
4254 | } | |
4255 | ptr = end; | |
4256 | } | |
93204d3a | 4257 | free (map); |
e489d0ae PB |
4258 | return FALSE; |
4259 | } | |
4260 | ||
252b5132 RH |
4261 | #define ELF_ARCH bfd_arch_arm |
4262 | #define ELF_MACHINE_CODE EM_ARM | |
d0facd1b NC |
4263 | #ifdef __QNXTARGET__ |
4264 | #define ELF_MAXPAGESIZE 0x1000 | |
4265 | #else | |
f21f3fe0 | 4266 | #define ELF_MAXPAGESIZE 0x8000 |
d0facd1b | 4267 | #endif |
252b5132 | 4268 | |
99e4ae17 AJ |
4269 | #define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data |
4270 | #define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data | |
252b5132 RH |
4271 | #define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags |
4272 | #define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data | |
4273 | #define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create | |
dc810e39 | 4274 | #define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup |
252b5132 | 4275 | #define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line |
e489d0ae | 4276 | #define bfd_elf32_new_section_hook elf32_arm_new_section_hook |
252b5132 RH |
4277 | |
4278 | #define elf_backend_get_symbol_type elf32_arm_get_symbol_type | |
4279 | #define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook | |
4280 | #define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook | |
4281 | #define elf_backend_check_relocs elf32_arm_check_relocs | |
dc810e39 | 4282 | #define elf_backend_relocate_section elf32_arm_relocate_section |
e489d0ae | 4283 | #define elf_backend_write_section elf32_arm_write_section |
252b5132 | 4284 | #define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol |
5e681ec4 | 4285 | #define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections |
252b5132 RH |
4286 | #define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol |
4287 | #define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections | |
e489d0ae | 4288 | #define elf_backend_link_output_symbol_hook elf32_arm_output_symbol_hook |
252b5132 | 4289 | #define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections |
ba96a88f | 4290 | #define elf_backend_post_process_headers elf32_arm_post_process_headers |
99e4ae17 | 4291 | #define elf_backend_reloc_type_class elf32_arm_reloc_type_class |
c178919b | 4292 | #define elf_backend_object_p elf32_arm_object_p |
e16bb312 NC |
4293 | #define elf_backend_section_flags elf32_arm_section_flags |
4294 | #define elf_backend_final_write_processing elf32_arm_final_write_processing | |
5e681ec4 | 4295 | #define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol |
252b5132 | 4296 | |
5e681ec4 | 4297 | #define elf_backend_can_refcount 1 |
252b5132 RH |
4298 | #define elf_backend_can_gc_sections 1 |
4299 | #define elf_backend_plt_readonly 1 | |
4300 | #define elf_backend_want_got_plt 1 | |
4301 | #define elf_backend_want_plt_sym 0 | |
acf8aed4 | 4302 | #if !USE_REL |
b491616a AM |
4303 | #define elf_backend_rela_normal 1 |
4304 | #endif | |
252b5132 | 4305 | |
04f7c78d | 4306 | #define elf_backend_got_header_size 12 |
04f7c78d | 4307 | |
252b5132 | 4308 | #include "elf32-target.h" |