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