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