Commit | Line | Data |
---|---|---|
177b1932 | 1 | /* BFD back-end for ARM COFF files. |
46686c78 | 2 | Copyright 1990, 91, 92, 93, 94, 95, 96, 1997 Free Software Foundation, Inc. |
943fbd5b KR |
3 | Written by Cygnus Support. |
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 | ||
21 | #include "bfd.h" | |
22 | #include "sysdep.h" | |
23 | #include "libbfd.h" | |
943fbd5b KR |
24 | |
25 | #include "coff/arm.h" | |
26 | ||
27 | #include "coff/internal.h" | |
28 | ||
29 | #ifdef COFF_WITH_PE | |
30 | #include "coff/pe.h" | |
31 | #endif | |
32 | ||
33 | #include "libcoff.h" | |
34 | ||
e1aeb285 NC |
35 | #define APCS_26_FLAG( abfd ) (coff_data (abfd)->flags & F_APCS_26) |
36 | #define APCS_FLOAT_FLAG( abfd ) (coff_data (abfd)->flags & F_APCS_FLOAT) | |
37 | #define PIC_FLAG( abfd ) (coff_data (abfd)->flags & F_PIC) | |
38 | #define APCS_SET( abfd ) (coff_data (abfd)->flags & F_APCS_SET) | |
39 | #define SET_APCS_FLAGS( abfd, flgs) (coff_data (abfd)->flags = \ | |
40 | (coff_data (abfd)->flags & ~ (F_APCS_26 | F_APCS_FLOAT | F_PIC)) \ | |
41 | | (flgs | F_APCS_SET)) | |
42 | #define INTERWORK_FLAG( abfd ) (coff_data (abfd)->flags & F_INTERWORK) | |
43 | #define INTERWORK_SET( abfd ) (coff_data (abfd)->flags & F_INTERWORK_SET) | |
44 | #define SET_INTERWORK_FLAG( abfd, flg ) (coff_data (abfd)->flags = \ | |
45 | (coff_data (abfd)->flags & ~ F_INTERWORK) \ | |
46 | | (flg | F_INTERWORK_SET)) | |
47 | ||
48 | ||
49 | static boolean coff_arm_relocate_section | |
50 | PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, | |
51 | struct internal_reloc *, struct internal_syment *, asection **)); | |
52 | ||
943fbd5b KR |
53 | static bfd_reloc_status_type |
54 | aoutarm_fix_pcrel_26_done PARAMS ((bfd *, arelent *, asymbol *, PTR, | |
55 | asection *, bfd *, char **)); | |
56 | ||
57 | static bfd_reloc_status_type | |
58 | aoutarm_fix_pcrel_26 PARAMS ((bfd *, arelent *, asymbol *, PTR, | |
59 | asection *, bfd *, char **)); | |
60 | ||
e1aeb285 NC |
61 | static bfd_reloc_status_type |
62 | coff_thumb_pcrel_23 PARAMS ((bfd *, arelent *, asymbol *, PTR, | |
63 | asection *, bfd *, char **)); | |
64 | ||
65 | static bfd_reloc_status_type | |
66 | coff_thumb_pcrel_12 PARAMS ((bfd *, arelent *, asymbol *, PTR, | |
67 | asection *, bfd *, char **)); | |
68 | ||
69 | static bfd_reloc_status_type | |
70 | coff_thumb_pcrel_9 PARAMS ((bfd *, arelent *, asymbol *, PTR, | |
71 | asection *, bfd *, char **)); | |
72 | ||
73 | static bfd_reloc_status_type | |
74 | coff_arm_reloc PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, | |
75 | char **)); | |
943fbd5b | 76 | |
e1aeb285 NC |
77 | static boolean |
78 | coff_arm_adjust_symndx PARAMS ((bfd *, struct bfd_link_info *, bfd *, | |
79 | asection *, struct internal_reloc *, | |
80 | boolean *)); | |
81 | ||
82 | /* The linker script knows the section names for placement. | |
83 | The entry_names are used to do simple name mangling on the stubs. | |
84 | Given a function name, and its type, the stub can be found. The | |
85 | name can be changed. The only requirement is the %s be present. | |
86 | */ | |
87 | ||
88 | #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t" | |
89 | #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb" | |
90 | ||
91 | #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7" | |
92 | #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm" | |
275143eb SC |
93 | |
94 | /* Used by the assembler. */ | |
943fbd5b KR |
95 | static bfd_reloc_status_type |
96 | coff_arm_reloc (abfd, reloc_entry, symbol, data, input_section, output_bfd, | |
97 | error_message) | |
98 | bfd *abfd; | |
99 | arelent *reloc_entry; | |
100 | asymbol *symbol; | |
101 | PTR data; | |
102 | asection *input_section; | |
103 | bfd *output_bfd; | |
104 | char **error_message; | |
105 | { | |
106 | symvalue diff; | |
943fbd5b KR |
107 | if (output_bfd == (bfd *) NULL) |
108 | return bfd_reloc_continue; | |
109 | ||
da7afe3b | 110 | diff = reloc_entry->addend; |
943fbd5b KR |
111 | |
112 | #define DOIT(x) \ | |
113 | x = ((x & ~howto->dst_mask) | (((x & howto->src_mask) + diff) & howto->dst_mask)) | |
114 | ||
da7afe3b SC |
115 | if (diff != 0) |
116 | { | |
117 | reloc_howto_type *howto = reloc_entry->howto; | |
118 | unsigned char *addr = (unsigned char *) data + reloc_entry->address; | |
943fbd5b | 119 | |
da7afe3b | 120 | switch (howto->size) |
943fbd5b | 121 | { |
da7afe3b SC |
122 | case 0: |
123 | { | |
124 | char x = bfd_get_8 (abfd, addr); | |
125 | DOIT (x); | |
126 | bfd_put_8 (abfd, x, addr); | |
127 | } | |
128 | break; | |
129 | ||
130 | case 1: | |
131 | { | |
132 | short x = bfd_get_16 (abfd, addr); | |
133 | DOIT (x); | |
134 | bfd_put_16 (abfd, x, addr); | |
135 | } | |
136 | break; | |
137 | ||
138 | case 2: | |
139 | { | |
140 | long x = bfd_get_32 (abfd, addr); | |
141 | DOIT (x); | |
142 | bfd_put_32 (abfd, x, addr); | |
143 | } | |
144 | break; | |
145 | ||
146 | default: | |
147 | abort (); | |
943fbd5b | 148 | } |
da7afe3b | 149 | } |
943fbd5b KR |
150 | |
151 | /* Now let bfd_perform_relocation finish everything up. */ | |
152 | return bfd_reloc_continue; | |
153 | } | |
154 | ||
e1aeb285 NC |
155 | #define TARGET_UNDERSCORE '_' |
156 | ||
3ea928f5 SC |
157 | #ifndef PCRELOFFSET |
158 | #define PCRELOFFSET true | |
159 | #endif | |
160 | ||
e1aeb285 NC |
161 | /* These most certainly belong somewhere else. Just had to get rid of |
162 | the manifest constants in the code. */ | |
163 | ||
164 | #define ARM_8 0 | |
165 | #define ARM_16 1 | |
166 | #define ARM_32 2 | |
167 | #define ARM_26 3 | |
168 | #define ARM_DISP8 4 | |
169 | #define ARM_DISP16 5 | |
170 | #define ARM_DISP32 6 | |
171 | #define ARM_26D 7 | |
172 | /* 8 is unused */ | |
173 | #define ARM_NEG16 9 | |
174 | #define ARM_NEG32 10 | |
175 | #define ARM_RVA32 11 | |
176 | #define ARM_THUMB9 12 | |
177 | #define ARM_THUMB12 13 | |
178 | #define ARM_THUMB23 14 | |
179 | ||
943fbd5b KR |
180 | static reloc_howto_type aoutarm_std_reloc_howto[] = |
181 | { | |
182 | /* type rs size bsz pcrel bitpos ovrf sf name part_inpl readmask setmask pcdone */ | |
e1aeb285 NC |
183 | HOWTO(ARM_8, /* type */ |
184 | 0, /* rightshift */ | |
943fbd5b | 185 | 0, /* size */ |
e1aeb285 NC |
186 | 8, /* bitsize */ |
187 | false, /* pc_relative */ | |
943fbd5b | 188 | 0, /* bitpos */ |
e1aeb285 NC |
189 | complain_overflow_bitfield, /* complain_on_overflow */ |
190 | coff_arm_reloc, /* special_function */ | |
191 | "ARM_8", /* name */ | |
192 | true, /* partial_inplace */ | |
193 | 0x000000ff, /* src_mask */ | |
194 | 0x000000ff, /* dst_mask */ | |
195 | PCRELOFFSET /* pcrel_offset */), | |
196 | HOWTO(ARM_16, | |
943fbd5b KR |
197 | 0, |
198 | 1, | |
199 | 16, | |
200 | false, | |
201 | 0, | |
202 | complain_overflow_bitfield, | |
203 | coff_arm_reloc, | |
e1aeb285 | 204 | "ARM_16", |
943fbd5b KR |
205 | true, |
206 | 0x0000ffff, | |
207 | 0x0000ffff, | |
208 | PCRELOFFSET), | |
e1aeb285 | 209 | HOWTO(ARM_32, |
943fbd5b KR |
210 | 0, |
211 | 2, | |
212 | 32, | |
213 | false, | |
214 | 0, | |
215 | complain_overflow_bitfield, | |
216 | coff_arm_reloc, | |
e1aeb285 | 217 | "ARM_32", |
943fbd5b KR |
218 | true, |
219 | 0xffffffff, | |
220 | 0xffffffff, | |
221 | PCRELOFFSET), | |
e1aeb285 | 222 | HOWTO(ARM_26, |
943fbd5b | 223 | 2, |
3ea928f5 | 224 | 2, |
943fbd5b KR |
225 | 26, |
226 | true, | |
227 | 0, | |
228 | complain_overflow_signed, | |
229 | aoutarm_fix_pcrel_26 , | |
e1aeb285 | 230 | "ARM_26", |
275143eb | 231 | false, |
943fbd5b KR |
232 | 0x00ffffff, |
233 | 0x00ffffff, | |
234 | PCRELOFFSET), | |
e1aeb285 | 235 | HOWTO(ARM_DISP8, |
943fbd5b KR |
236 | 0, |
237 | 0, | |
238 | 8, | |
239 | true, | |
240 | 0, | |
241 | complain_overflow_signed, | |
242 | coff_arm_reloc, | |
e1aeb285 | 243 | "ARM_DISP8", |
943fbd5b KR |
244 | true, |
245 | 0x000000ff, | |
246 | 0x000000ff, | |
247 | true), | |
e1aeb285 | 248 | HOWTO( ARM_DISP16, |
943fbd5b KR |
249 | 0, |
250 | 1, | |
251 | 16, | |
252 | true, | |
253 | 0, | |
254 | complain_overflow_signed, | |
255 | coff_arm_reloc, | |
e1aeb285 | 256 | "ARM_DISP16", |
943fbd5b KR |
257 | true, |
258 | 0x0000ffff, | |
259 | 0x0000ffff, | |
260 | true), | |
e1aeb285 | 261 | HOWTO( ARM_DISP32, |
943fbd5b KR |
262 | 0, |
263 | 2, | |
264 | 32, | |
265 | true, | |
266 | 0, | |
267 | complain_overflow_signed, | |
268 | coff_arm_reloc, | |
e1aeb285 | 269 | "ARM_DISP32", |
943fbd5b KR |
270 | true, |
271 | 0xffffffff, | |
272 | 0xffffffff, | |
273 | true), | |
e1aeb285 | 274 | HOWTO( ARM_26D, |
943fbd5b | 275 | 2, |
3ea928f5 | 276 | 2, |
943fbd5b KR |
277 | 26, |
278 | false, | |
279 | 0, | |
280 | complain_overflow_signed, | |
281 | aoutarm_fix_pcrel_26_done, | |
e1aeb285 | 282 | "ARM_26D", |
943fbd5b KR |
283 | true, |
284 | 0x00ffffff, | |
46686c78 | 285 | 0x0, |
943fbd5b | 286 | false), |
e1aeb285 | 287 | /* 8 is unused */ |
943fbd5b | 288 | {-1}, |
e1aeb285 | 289 | HOWTO( ARM_NEG16, |
943fbd5b KR |
290 | 0, |
291 | -1, | |
292 | 16, | |
293 | false, | |
294 | 0, | |
295 | complain_overflow_bitfield, | |
296 | coff_arm_reloc, | |
e1aeb285 | 297 | "ARM_NEG16", |
943fbd5b KR |
298 | true, |
299 | 0x0000ffff, | |
300 | 0x0000ffff, | |
301 | false), | |
e1aeb285 | 302 | HOWTO( ARM_NEG32, |
943fbd5b KR |
303 | 0, |
304 | -2, | |
305 | 32, | |
306 | false, | |
307 | 0, | |
308 | complain_overflow_bitfield, | |
309 | coff_arm_reloc, | |
e1aeb285 | 310 | "ARM_NEG32", |
943fbd5b KR |
311 | true, |
312 | 0xffffffff, | |
313 | 0xffffffff, | |
3ea928f5 | 314 | false), |
e1aeb285 | 315 | HOWTO( ARM_RVA32, |
3ea928f5 SC |
316 | 0, |
317 | 2, | |
318 | 32, | |
319 | false, | |
320 | 0, | |
321 | complain_overflow_bitfield, | |
322 | coff_arm_reloc, | |
e1aeb285 | 323 | "ARM_RVA32", |
3ea928f5 SC |
324 | true, |
325 | 0xffffffff, | |
326 | 0xffffffff, | |
327 | PCRELOFFSET), | |
e1aeb285 NC |
328 | HOWTO( ARM_THUMB9, |
329 | 1, | |
330 | 1, | |
331 | 9, | |
332 | true, | |
333 | 0, | |
334 | complain_overflow_signed, | |
335 | coff_thumb_pcrel_9 , | |
336 | "ARM_THUMB9", | |
337 | false, | |
338 | 0x000000ff, | |
339 | 0x000000ff, | |
340 | PCRELOFFSET), | |
341 | HOWTO( ARM_THUMB12, | |
342 | 1, | |
343 | 1, | |
344 | 12, | |
345 | true, | |
346 | 0, | |
347 | complain_overflow_signed, | |
348 | coff_thumb_pcrel_12 , | |
349 | "ARM_THUMB12", | |
350 | false, | |
351 | 0x000007ff, | |
352 | 0x000007ff, | |
353 | PCRELOFFSET), | |
354 | HOWTO( ARM_THUMB23, | |
355 | 1, | |
356 | 2, | |
357 | 23, | |
358 | true, | |
359 | 0, | |
360 | complain_overflow_signed, | |
361 | coff_thumb_pcrel_23 , | |
362 | "ARM_THUMB23", | |
363 | false, | |
364 | 0x07ff07ff, | |
365 | 0x07ff07ff, | |
366 | PCRELOFFSET), | |
943fbd5b | 367 | }; |
177b1932 DE |
368 | #ifdef COFF_WITH_PE |
369 | /* Return true if this relocation should | |
370 | appear in the output .reloc section. */ | |
371 | ||
372 | static boolean in_reloc_p (abfd, howto) | |
373 | bfd * abfd; | |
374 | reloc_howto_type *howto; | |
375 | { | |
376 | return !howto->pc_relative && howto->type != 11; | |
377 | } | |
378 | #endif | |
943fbd5b KR |
379 | |
380 | ||
943fbd5b KR |
381 | #define RTYPE2HOWTO(cache_ptr, dst) \ |
382 | (cache_ptr)->howto = aoutarm_std_reloc_howto + (dst)->r_type; | |
383 | ||
275143eb | 384 | #define coff_rtype_to_howto coff_arm_rtype_to_howto |
a5655244 | 385 | |
275143eb SC |
386 | static reloc_howto_type * |
387 | coff_arm_rtype_to_howto (abfd, sec, rel, h, sym, addendp) | |
388 | bfd *abfd; | |
389 | asection *sec; | |
390 | struct internal_reloc *rel; | |
391 | struct coff_link_hash_entry *h; | |
392 | struct internal_syment *sym; | |
393 | bfd_vma *addendp; | |
394 | { | |
395 | reloc_howto_type *howto; | |
396 | ||
397 | howto = aoutarm_std_reloc_howto + rel->r_type; | |
398 | ||
e1aeb285 | 399 | if (rel->r_type == ARM_RVA32) |
275143eb | 400 | { |
a5655244 | 401 | *addendp -= pe_data(sec->output_section->owner)->pe_opthdr.ImageBase; |
275143eb | 402 | } |
46686c78 NC |
403 | |
404 | /* The relocation_section function will skip pcrel_offset relocs | |
405 | when doing a relocateable link. However, we want to convert | |
406 | ARM26 to ARM26D relocs if possible. We return a fake howto in | |
407 | this case without pcrel_offset set, and adjust the addend to | |
408 | compensate. */ | |
e1aeb285 | 409 | if (rel->r_type == ARM_26 |
46686c78 NC |
410 | && h != NULL |
411 | && (h->root.type == bfd_link_hash_defined | |
412 | || h->root.type == bfd_link_hash_defweak) | |
413 | && h->root.u.def.section->output_section == sec->output_section) | |
414 | { | |
415 | static reloc_howto_type fake_arm26_reloc = | |
e1aeb285 | 416 | HOWTO (ARM_26, |
46686c78 NC |
417 | 2, |
418 | 2, | |
419 | 26, | |
420 | true, | |
421 | 0, | |
422 | complain_overflow_signed, | |
423 | aoutarm_fix_pcrel_26 , | |
e1aeb285 | 424 | "ARM_26", |
46686c78 NC |
425 | false, |
426 | 0x00ffffff, | |
427 | 0x00ffffff, | |
428 | false); | |
429 | ||
430 | *addendp -= rel->r_vaddr - sec->vma; | |
e1aeb285 | 431 | return & fake_arm26_reloc; |
46686c78 NC |
432 | } |
433 | ||
275143eb SC |
434 | return howto; |
435 | ||
436 | } | |
437 | /* Used by the assembler. */ | |
438 | ||
943fbd5b KR |
439 | static bfd_reloc_status_type |
440 | aoutarm_fix_pcrel_26_done (abfd, reloc_entry, symbol, data, input_section, | |
441 | output_bfd, error_message) | |
442 | bfd *abfd; | |
443 | arelent *reloc_entry; | |
444 | asymbol *symbol; | |
445 | PTR data; | |
446 | asection *input_section; | |
447 | bfd *output_bfd; | |
448 | char **error_message; | |
449 | { | |
450 | /* This is dead simple at present. */ | |
451 | return bfd_reloc_ok; | |
452 | } | |
453 | ||
275143eb SC |
454 | /* Used by the assembler. */ |
455 | ||
943fbd5b KR |
456 | static bfd_reloc_status_type |
457 | aoutarm_fix_pcrel_26 (abfd, reloc_entry, symbol, data, input_section, | |
458 | output_bfd, error_message) | |
459 | bfd *abfd; | |
460 | arelent *reloc_entry; | |
461 | asymbol *symbol; | |
462 | PTR data; | |
463 | asection *input_section; | |
464 | bfd *output_bfd; | |
465 | char **error_message; | |
466 | { | |
467 | bfd_vma relocation; | |
468 | bfd_size_type addr = reloc_entry->address; | |
469 | long target = bfd_get_32 (abfd, (bfd_byte *) data + addr); | |
470 | bfd_reloc_status_type flag = bfd_reloc_ok; | |
471 | ||
472 | /* If this is an undefined symbol, return error */ | |
473 | if (symbol->section == &bfd_und_section | |
474 | && (symbol->flags & BSF_WEAK) == 0) | |
475 | return output_bfd ? bfd_reloc_continue : bfd_reloc_undefined; | |
476 | ||
477 | /* If the sections are different, and we are doing a partial relocation, | |
478 | just ignore it for now. */ | |
479 | if (symbol->section->name != input_section->name | |
480 | && output_bfd != (bfd *)NULL) | |
481 | return bfd_reloc_continue; | |
482 | ||
483 | relocation = (target & 0x00ffffff) << 2; | |
484 | relocation = (relocation ^ 0x02000000) - 0x02000000; /* Sign extend */ | |
485 | relocation += symbol->value; | |
486 | relocation += symbol->section->output_section->vma; | |
487 | relocation += symbol->section->output_offset; | |
488 | relocation += reloc_entry->addend; | |
489 | relocation -= input_section->output_section->vma; | |
490 | relocation -= input_section->output_offset; | |
491 | relocation -= addr; | |
e1aeb285 | 492 | |
943fbd5b KR |
493 | if (relocation & 3) |
494 | return bfd_reloc_overflow; | |
495 | ||
496 | /* Check for overflow */ | |
497 | if (relocation & 0x02000000) | |
498 | { | |
499 | if ((relocation & ~0x03ffffff) != ~0x03ffffff) | |
500 | flag = bfd_reloc_overflow; | |
501 | } | |
502 | else if (relocation & ~0x03ffffff) | |
503 | flag = bfd_reloc_overflow; | |
504 | ||
505 | target &= ~0x00ffffff; | |
506 | target |= (relocation >> 2) & 0x00ffffff; | |
507 | bfd_put_32 (abfd, target, (bfd_byte *) data + addr); | |
508 | ||
509 | /* Now the ARM magic... Change the reloc type so that it is marked as done. | |
510 | Strictly this is only necessary if we are doing a partial relocation. */ | |
e1aeb285 NC |
511 | reloc_entry->howto = &aoutarm_std_reloc_howto[ARM_26D]; |
512 | ||
513 | return flag; | |
514 | } | |
515 | ||
516 | typedef enum {bunknown, b9, b12, b23} thumb_pcrel_branchtype; | |
517 | ||
518 | static bfd_reloc_status_type | |
519 | coff_thumb_pcrel_common (abfd, reloc_entry, symbol, data, input_section, | |
520 | output_bfd, error_message, btype) | |
521 | bfd *abfd; | |
522 | arelent *reloc_entry; | |
523 | asymbol *symbol; | |
524 | PTR data; | |
525 | asection *input_section; | |
526 | bfd *output_bfd; | |
527 | char **error_message; | |
528 | thumb_pcrel_branchtype btype; | |
529 | { | |
530 | bfd_vma relocation; | |
531 | bfd_size_type addr = reloc_entry->address; | |
532 | long target = bfd_get_32 (abfd, (bfd_byte *) data + addr); | |
533 | bfd_reloc_status_type flag = bfd_reloc_ok; | |
534 | bfd_vma dstmsk; | |
535 | bfd_vma offmsk; | |
536 | bfd_vma signbit; | |
537 | ||
538 | /* NOTE: This routine is currently used by GAS, but not by the link | |
539 | phase. */ | |
540 | ||
541 | switch (btype) | |
542 | { | |
543 | case b9: | |
544 | dstmsk = 0x000000ff; | |
545 | offmsk = 0x000001fe; | |
546 | signbit = 0x00000100; | |
547 | break; | |
548 | ||
549 | case b12: | |
550 | dstmsk = 0x000007ff; | |
551 | offmsk = 0x00000ffe; | |
552 | signbit = 0x00000800; | |
553 | break; | |
554 | ||
555 | case b23: | |
556 | dstmsk = 0x07ff07ff; | |
557 | offmsk = 0x007fffff; | |
558 | signbit = 0x00400000; | |
559 | break; | |
560 | ||
561 | default: | |
562 | abort (); | |
563 | } | |
564 | ||
565 | /* If this is an undefined symbol, return error */ | |
566 | if (symbol->section == &bfd_und_section | |
567 | && (symbol->flags & BSF_WEAK) == 0) | |
568 | return output_bfd ? bfd_reloc_continue : bfd_reloc_undefined; | |
569 | ||
570 | /* If the sections are different, and we are doing a partial relocation, | |
571 | just ignore it for now. */ | |
572 | if (symbol->section->name != input_section->name | |
573 | && output_bfd != (bfd *)NULL) | |
574 | return bfd_reloc_continue; | |
575 | ||
576 | switch (btype) | |
577 | { | |
578 | case b9: | |
579 | case b12: | |
580 | relocation = ((target & dstmsk) << 1); | |
581 | break; | |
582 | ||
583 | case b23: | |
584 | if (bfd_big_endian (abfd)) | |
585 | relocation = ((target & 0x7ff) << 1) | ((target & 0x07ff0000) >> 4); | |
586 | else | |
587 | relocation = ((target & 0x7ff) << 12) | ((target & 0x07ff0000) >> 15); | |
588 | break; | |
589 | } | |
590 | ||
591 | relocation = (relocation ^ signbit) - signbit; /* Sign extend */ | |
592 | relocation += symbol->value; | |
593 | relocation += symbol->section->output_section->vma; | |
594 | relocation += symbol->section->output_offset; | |
595 | relocation += reloc_entry->addend; | |
596 | relocation -= input_section->output_section->vma; | |
597 | relocation -= input_section->output_offset; | |
598 | relocation -= addr; | |
599 | ||
600 | if (relocation & 1) | |
601 | return bfd_reloc_overflow; | |
602 | ||
603 | /* Check for overflow */ | |
604 | if (relocation & signbit) | |
605 | { | |
606 | if ((relocation & ~offmsk) != ~offmsk) | |
607 | flag = bfd_reloc_overflow; | |
608 | } | |
609 | else if (relocation & ~offmsk) | |
610 | flag = bfd_reloc_overflow; | |
611 | ||
612 | target &= ~dstmsk; | |
613 | switch (btype) | |
614 | { | |
615 | case b9: | |
616 | case b12: | |
617 | target |= (relocation >> 1); | |
618 | break; | |
619 | ||
620 | case b23: | |
621 | if (bfd_big_endian (abfd)) | |
622 | target |= ((relocation & 0xfff) >> 1) | ((relocation << 4) & 0x07ff0000); | |
623 | else | |
624 | target |= ((relocation & 0xffe) << 15) | ((relocation >> 12) & 0x7ff); | |
625 | break; | |
626 | } | |
275143eb | 627 | |
e1aeb285 NC |
628 | bfd_put_32 (abfd, target, (bfd_byte *) data + addr); |
629 | ||
630 | /* Now the ARM magic... Change the reloc type so that it is marked as done. | |
631 | Strictly this is only necessary if we are doing a partial relocation. */ | |
632 | reloc_entry->howto = & aoutarm_std_reloc_howto [ARM_26D]; | |
633 | ||
634 | /* TODO: We should possibly have DONE entries for the THUMB PCREL relocations */ | |
943fbd5b KR |
635 | return flag; |
636 | } | |
637 | ||
e1aeb285 NC |
638 | static bfd_reloc_status_type |
639 | coff_thumb_pcrel_23 (abfd, reloc_entry, symbol, data, input_section, | |
640 | output_bfd, error_message) | |
641 | bfd *abfd; | |
642 | arelent *reloc_entry; | |
643 | asymbol *symbol; | |
644 | PTR data; | |
645 | asection *input_section; | |
646 | bfd *output_bfd; | |
647 | char **error_message; | |
648 | { | |
649 | return coff_thumb_pcrel_common (abfd, reloc_entry, symbol, data, | |
650 | input_section, output_bfd, error_message, b23); | |
651 | } | |
652 | ||
653 | static bfd_reloc_status_type | |
654 | coff_thumb_pcrel_12 (abfd, reloc_entry, symbol, data, input_section, | |
655 | output_bfd, error_message) | |
656 | bfd *abfd; | |
657 | arelent *reloc_entry; | |
658 | asymbol *symbol; | |
659 | PTR data; | |
660 | asection *input_section; | |
661 | bfd *output_bfd; | |
662 | char **error_message; | |
663 | { | |
664 | return coff_thumb_pcrel_common (abfd, reloc_entry, symbol, data, | |
665 | input_section, output_bfd, error_message, b12); | |
666 | } | |
667 | ||
668 | static bfd_reloc_status_type | |
669 | coff_thumb_pcrel_9 (abfd, reloc_entry, symbol, data, input_section, | |
670 | output_bfd, error_message) | |
671 | bfd *abfd; | |
672 | arelent *reloc_entry; | |
673 | asymbol *symbol; | |
674 | PTR data; | |
675 | asection *input_section; | |
676 | bfd *output_bfd; | |
677 | char **error_message; | |
678 | { | |
679 | return coff_thumb_pcrel_common (abfd, reloc_entry, symbol, data, | |
680 | input_section, output_bfd, error_message, b9); | |
681 | } | |
682 | ||
275143eb | 683 | |
943fbd5b KR |
684 | static CONST struct reloc_howto_struct * |
685 | arm_reloc_type_lookup(abfd,code) | |
686 | bfd *abfd; | |
687 | bfd_reloc_code_real_type code; | |
688 | { | |
689 | #define ASTD(i,j) case i: return &aoutarm_std_reloc_howto[j] | |
690 | if (code == BFD_RELOC_CTOR) | |
691 | switch (bfd_get_arch_info (abfd)->bits_per_address) | |
692 | { | |
693 | case 32: | |
694 | code = BFD_RELOC_32; | |
695 | break; | |
696 | default: return (CONST struct reloc_howto_struct *) 0; | |
697 | } | |
698 | ||
699 | switch (code) | |
700 | { | |
e1aeb285 NC |
701 | ASTD (BFD_RELOC_8, ARM_8); |
702 | ASTD (BFD_RELOC_16, ARM_16); | |
703 | ASTD (BFD_RELOC_32, ARM_32); | |
704 | ASTD (BFD_RELOC_ARM_PCREL_BRANCH, ARM_26); | |
705 | ASTD (BFD_RELOC_8_PCREL, ARM_DISP8); | |
706 | ASTD (BFD_RELOC_16_PCREL, ARM_DISP16); | |
707 | ASTD (BFD_RELOC_32_PCREL, ARM_DISP32); | |
708 | ASTD (BFD_RELOC_RVA, ARM_RVA32); | |
709 | ASTD (BFD_RELOC_THUMB_PCREL_BRANCH9, ARM_THUMB9); | |
710 | ASTD (BFD_RELOC_THUMB_PCREL_BRANCH12, ARM_THUMB12); | |
711 | ASTD (BFD_RELOC_THUMB_PCREL_BRANCH23, ARM_THUMB23); | |
943fbd5b KR |
712 | default: return (CONST struct reloc_howto_struct *) 0; |
713 | } | |
714 | } | |
715 | ||
716 | ||
717 | #define coff_bfd_reloc_type_lookup arm_reloc_type_lookup | |
718 | ||
943fbd5b | 719 | #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (2) |
943fbd5b | 720 | #define COFF_PAGE_SIZE 0x1000 |
943fbd5b KR |
721 | /* Turn a howto into a reloc nunmber */ |
722 | ||
723 | #define SELECT_RELOC(x,howto) { x.r_type = howto->type; } | |
724 | #define BADMAG(x) ARMBADMAG(x) | |
725 | #define ARM 1 /* Customize coffcode.h */ | |
726 | ||
e1aeb285 NC |
727 | /* The set of global variables that mark the total size of each kind |
728 | of glue required. */ | |
729 | long int global_thumb_glue_size = 0; | |
730 | long int global_arm_glue_size = 0; | |
731 | ||
732 | bfd* bfd_of_glue_owner = 0; | |
733 | ||
734 | /* some typedefs for holding instructions */ | |
735 | typedef unsigned long int insn32; | |
736 | typedef unsigned short int insn16; | |
737 | ||
738 | \f | |
739 | /* The thumb form of a long branch is a bit finicky, because the offset | |
740 | encoding is split over two fields, each in it's own instruction. They | |
741 | can occur in any order. So given a thumb form of long branch, and an | |
742 | offset, insert the offset into the thumb branch and return finished | |
743 | instruction. | |
744 | ||
745 | It takes two thumb instructions to encode the target address. Each has | |
746 | 11 bits to invest. The upper 11 bits are stored in one (identifed by | |
747 | H-0.. see below), the lower 11 bits are stored in the other (identified | |
748 | by H-1). | |
749 | ||
750 | Combine together and shifted left by 1 (it's a half word address) and | |
751 | there you have it. | |
752 | ||
753 | Op: 1111 = F, | |
754 | H-0, upper address-0 = 000 | |
755 | Op: 1111 = F, | |
756 | H-1, lower address-0 = 800 | |
757 | ||
758 | They can be ordered either way, but the arm tools I've seen always put | |
759 | the lower one first. It probably doesn't matter. krk@cygnus.com | |
760 | ||
761 | XXX: Actually the order does matter. The second instruction (H-1) | |
762 | moves the computed address into the PC, so it must be the second one | |
763 | in the sequence. The problem, however is that whilst little endian code | |
764 | stores the instructions in HI then LOW order, big endian code does the | |
765 | reverse. nickc@cygnus.com */ | |
766 | ||
767 | #define LOW_HI_ORDER 0xF800F000 | |
768 | #define HI_LOW_ORDER 0xF000F800 | |
769 | ||
770 | static insn32 | |
771 | insert_thumb_branch (br_insn, rel_off) | |
772 | insn32 br_insn; | |
773 | int rel_off; | |
774 | { | |
775 | unsigned int low_bits; | |
776 | unsigned int high_bits; | |
943fbd5b | 777 | |
46686c78 | 778 | |
e1aeb285 | 779 | BFD_ASSERT((rel_off & 1) != 1); |
46686c78 | 780 | |
e1aeb285 NC |
781 | rel_off >>= 1; /* half word aligned address */ |
782 | low_bits = rel_off & 0x000007FF; /* the bottom 11 bits */ | |
783 | high_bits = ( rel_off >> 11 ) & 0x000007FF; /* the top 11 bits */ | |
46686c78 | 784 | |
e1aeb285 NC |
785 | if ((br_insn & LOW_HI_ORDER) == LOW_HI_ORDER) |
786 | br_insn = LOW_HI_ORDER | (low_bits << 16) | high_bits; | |
787 | else if ((br_insn & HI_LOW_ORDER) == HI_LOW_ORDER) | |
788 | br_insn = HI_LOW_ORDER | (high_bits << 16) | low_bits; | |
789 | else | |
790 | abort(); /* error - not a valid branch instruction form */ | |
46686c78 | 791 | |
e1aeb285 | 792 | /* FIXME: abort is probably not the right call. krk@cygnus.com */ |
46686c78 | 793 | |
e1aeb285 NC |
794 | return br_insn; |
795 | } | |
46686c78 | 796 | |
e1aeb285 NC |
797 | \f |
798 | static struct coff_link_hash_entry * | |
799 | find_thumb_glue (info, name, input_bfd) | |
800 | struct bfd_link_info * info; | |
801 | char * name; | |
802 | bfd * input_bfd; | |
46686c78 | 803 | { |
e1aeb285 | 804 | char *tmp_name = 0; |
46686c78 | 805 | |
e1aeb285 | 806 | struct coff_link_hash_entry *myh = 0; |
46686c78 | 807 | |
e1aeb285 NC |
808 | tmp_name = ((char *) |
809 | bfd_malloc (strlen (name) + strlen (THUMB2ARM_GLUE_ENTRY_NAME))); | |
46686c78 | 810 | |
e1aeb285 | 811 | BFD_ASSERT (tmp_name); |
46686c78 | 812 | |
e1aeb285 NC |
813 | sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name); |
814 | ||
815 | myh = coff_link_hash_lookup (coff_hash_table (info), | |
816 | tmp_name, | |
817 | false, false, true); | |
818 | if (myh == NULL) | |
819 | { | |
820 | _bfd_error_handler ("%s: unable to find THUMB glue '%s' for `%s'", | |
821 | bfd_get_filename (input_bfd), tmp_name, name); | |
46686c78 NC |
822 | } |
823 | ||
e1aeb285 | 824 | free (tmp_name); |
46686c78 | 825 | |
e1aeb285 | 826 | return myh; |
46686c78 NC |
827 | } |
828 | ||
e1aeb285 NC |
829 | static struct coff_link_hash_entry * |
830 | find_arm_glue (info, name, input_bfd) | |
831 | struct bfd_link_info * info; | |
832 | char * name; | |
833 | bfd * input_bfd; | |
46686c78 | 834 | { |
e1aeb285 NC |
835 | char *tmp_name = 0; |
836 | struct coff_link_hash_entry *myh = 0; | |
315dc1f4 | 837 | |
e1aeb285 NC |
838 | tmp_name = ((char *) |
839 | bfd_malloc (strlen (name) + strlen (ARM2THUMB_GLUE_ENTRY_NAME))); | |
46686c78 | 840 | |
e1aeb285 | 841 | BFD_ASSERT (tmp_name); |
46686c78 | 842 | |
e1aeb285 NC |
843 | sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name); |
844 | ||
845 | myh = coff_link_hash_lookup (coff_hash_table (info), | |
846 | tmp_name, | |
847 | false, false, true); | |
46686c78 | 848 | |
e1aeb285 NC |
849 | if (myh == NULL) |
850 | { | |
851 | _bfd_error_handler ("%s: unable to find ARM glue '%s' for `%s'", | |
852 | bfd_get_filename (input_bfd), tmp_name, name); | |
853 | } | |
46686c78 | 854 | |
e1aeb285 | 855 | free (tmp_name); |
46686c78 | 856 | |
e1aeb285 NC |
857 | return myh; |
858 | } | |
46686c78 | 859 | |
e1aeb285 NC |
860 | /* |
861 | ARM->Thumb glue: | |
862 | ||
863 | .arm | |
864 | __func_from_arm: | |
865 | ldr r12, __func_addr | |
866 | bx r12 | |
867 | __func_addr: | |
868 | .word func @ behave as if you saw a ARM_32 reloc | |
869 | ||
870 | ldr ip,8 <__func_addr> e59fc000 | |
871 | bx ip e12fff1c | |
872 | .word func 00000001 | |
873 | ||
874 | */ | |
875 | ||
876 | #define ARM2THUMB_GLUE_SIZE 12 | |
877 | static insn32 | |
878 | a2t1_ldr_insn = 0xe59fc000, | |
879 | a2t2_bx_r12_insn = 0xe12fff1c, | |
880 | a2t3_func_addr_insn = 0x00000001; | |
881 | ||
882 | /* | |
883 | Thumb->ARM: | |
884 | ||
885 | .thumb | |
886 | .align 2 | |
887 | __func_from_thumb: | |
888 | bx pc | |
889 | nop | |
890 | .arm | |
891 | __func_change_to_arm: | |
892 | b func | |
893 | ||
894 | ||
895 | bx pc 4778 | |
896 | nop 0000 | |
897 | b func eafffffe | |
898 | ||
899 | */ | |
900 | ||
901 | #define THUMB2ARM_GLUE_SIZE 8 | |
902 | static insn16 | |
903 | t2a1_bx_pc_insn = 0x4778, | |
904 | t2a2_noop_insn = 0x46c0; | |
905 | static insn32 | |
906 | t2a3_b_insn = 0xea000000; | |
907 | ||
908 | /* TODO: | |
909 | We should really create new local (static) symbols in destination | |
910 | object for each stub we create. We should also create local | |
911 | (static) symbols within the stubs when switching between ARM and | |
912 | Thumb code. This will ensure that the debugger and disassembler | |
913 | can present a better view of stubs. | |
914 | ||
915 | We can treat stubs like literal sections, and for the THUMB9 ones | |
916 | (short addressing range) we should be able to insert the stubs | |
917 | between sections. i.e. the simplest approach (since relocations | |
918 | are done on a section basis) is to dump the stubs at the end of | |
919 | processing a section. That way we can always try and minimise the | |
920 | offset to and from a stub. However, this does not map well onto | |
921 | the way that the linker/BFD does its work: mapping all input | |
922 | sections to output sections via the linker script before doing | |
923 | all the processing. | |
924 | ||
925 | Unfortunately it may be easier to just to disallow short range | |
926 | Thumb->ARM stubs (i.e. no conditional inter-working branches, | |
927 | only branch-and-link (BL) calls. This will simplify the processing | |
928 | since we can then put all of the stubs into their own section. | |
929 | ||
930 | TODO: | |
931 | On a different subject, rather than complaining when a | |
932 | branch cannot fit in the number of bits available for the | |
933 | instruction we should generate a trampoline stub (needed to | |
934 | address the complete 32bit address space). */ | |
935 | ||
936 | /* The standard COFF backend linker does not cope with the special | |
937 | Thumb BRANCH23 relocation. The alternative would be to split the | |
938 | BRANCH23 into seperate HI23 and LO23 relocations. However, it is a | |
939 | bit simpler simply providing our own relocation driver. */ | |
940 | ||
941 | /* The reloc processing routine for the ARM/Thumb COFF linker. NOTE: | |
942 | This code is a very slightly modified copy of | |
943 | _bfd_coff_generic_relocate_section. It would be a much more | |
944 | maintainable solution to have a MACRO that could be expanded within | |
945 | _bfd_coff_generic_relocate_section that would only be provided for | |
946 | ARM/Thumb builds. It is only the code marked THUMBEXTENSION that | |
947 | is different from the original. */ | |
46686c78 | 948 | |
315dc1f4 | 949 | static boolean |
e1aeb285 NC |
950 | coff_arm_relocate_section (output_bfd, info, input_bfd, input_section, |
951 | contents, relocs, syms, sections) | |
952 | bfd *output_bfd; | |
953 | struct bfd_link_info *info; | |
954 | bfd *input_bfd; | |
955 | asection *input_section; | |
956 | bfd_byte *contents; | |
957 | struct internal_reloc *relocs; | |
958 | struct internal_syment *syms; | |
959 | asection **sections; | |
46686c78 | 960 | { |
e1aeb285 NC |
961 | struct internal_reloc *rel; |
962 | struct internal_reloc *relend; | |
46686c78 | 963 | |
e1aeb285 NC |
964 | rel = relocs; |
965 | relend = rel + input_section->reloc_count; | |
46686c78 | 966 | |
e1aeb285 | 967 | for (; rel < relend; rel++) |
46686c78 | 968 | { |
e1aeb285 NC |
969 | int done = 0; |
970 | long symndx; | |
971 | struct coff_link_hash_entry *h; | |
972 | struct internal_syment *sym; | |
973 | bfd_vma addend; | |
974 | bfd_vma val; | |
975 | reloc_howto_type *howto; | |
976 | bfd_reloc_status_type rstat; | |
977 | bfd_vma h_val; | |
978 | ||
979 | symndx = rel->r_symndx; | |
980 | ||
981 | if (symndx == -1) | |
46686c78 | 982 | { |
e1aeb285 NC |
983 | h = NULL; |
984 | sym = NULL; | |
46686c78 NC |
985 | } |
986 | else | |
e1aeb285 NC |
987 | { |
988 | h = obj_coff_sym_hashes (input_bfd)[symndx]; | |
989 | sym = syms + symndx; | |
990 | } | |
46686c78 | 991 | |
e1aeb285 NC |
992 | /* COFF treats common symbols in one of two ways. Either the |
993 | size of the symbol is included in the section contents, or it | |
994 | is not. We assume that the size is not included, and force | |
995 | the rtype_to_howto function to adjust the addend as needed. */ | |
46686c78 | 996 | |
e1aeb285 NC |
997 | if (sym != NULL && sym->n_scnum != 0) |
998 | addend = - sym->n_value; | |
999 | else | |
1000 | addend = 0; | |
1001 | ||
1002 | ||
1003 | howto = bfd_coff_rtype_to_howto (input_bfd, input_section, rel, h, | |
1004 | sym, &addend); | |
1005 | if (howto == NULL) | |
1006 | return false; | |
1007 | ||
1008 | /* If we are doing a relocateable link, then we can just ignore | |
1009 | a PC relative reloc that is pcrel_offset. It will already | |
1010 | have the correct value. If this is not a relocateable link, | |
1011 | then we should ignore the symbol value. */ | |
1012 | if (howto->pc_relative && howto->pcrel_offset) | |
1013 | { | |
1014 | if (info->relocateable) | |
1015 | continue; | |
1016 | if (sym != NULL && sym->n_scnum != 0) | |
1017 | addend += sym->n_value; | |
1018 | } | |
1019 | ||
1020 | /* If we are doing a relocateable link, then we can just ignore | |
1021 | a PC relative reloc that is pcrel_offset. It will already | |
1022 | have the correct value. */ | |
1023 | if (info->relocateable | |
1024 | && howto->pc_relative | |
1025 | && howto->pcrel_offset) | |
1026 | continue; | |
1027 | ||
1028 | val = 0; | |
1029 | ||
1030 | if (h == NULL) | |
1031 | { | |
1032 | asection *sec; | |
46686c78 | 1033 | |
e1aeb285 NC |
1034 | if (symndx == -1) |
1035 | { | |
1036 | sec = bfd_abs_section_ptr; | |
1037 | val = 0; | |
1038 | } | |
1039 | else | |
1040 | { | |
1041 | sec = sections[symndx]; | |
1042 | val = (sec->output_section->vma | |
1043 | + sec->output_offset | |
1044 | + sym->n_value | |
1045 | - sec->vma); | |
1046 | } | |
1047 | } | |
1048 | else | |
1049 | { | |
1050 | #if 1 /* THUMBEXTENSION */ | |
1051 | /* We don't output the stubs if we are generating a | |
1052 | relocatable output file, since we may as well leave the | |
1053 | stub generation to the final linker pass. If we fail to | |
1054 | verify that the name is defined, we'll try to build stubs | |
1055 | for an undefined name... */ | |
1056 | if (! info->relocateable | |
1057 | && ( h->root.type == bfd_link_hash_defined | |
1058 | || h->root.type == bfd_link_hash_defweak)) | |
1059 | { | |
1060 | asection * sec; | |
1061 | asection * h_sec = h->root.u.def.section; | |
1062 | const char * name = h->root.root.string; | |
1063 | ||
1064 | /* h locates the symbol referenced in the reloc. */ | |
1065 | h_val = (h->root.u.def.value | |
1066 | + h_sec->output_section->vma | |
1067 | + h_sec->output_offset); | |
1068 | ||
1069 | if (howto->type == ARM_26) | |
1070 | { | |
1071 | if ( h->class == C_THUMBSTATFUNC | |
1072 | || h->class == C_THUMBEXTFUNC) | |
1073 | { | |
1074 | /* Arm code calling a Thumb function */ | |
1075 | signed long int final_disp; | |
1076 | unsigned long int tmp; | |
1077 | long int my_offset; | |
1078 | long int offset; | |
1079 | asection * s = 0; | |
1080 | unsigned long int return_address; | |
1081 | long int ret_offset; | |
1082 | long int disp; | |
1083 | struct coff_link_hash_entry * myh; | |
1084 | ||
1085 | myh = find_arm_glue (info, name, input_bfd); | |
1086 | if (myh == NULL) | |
1087 | return false; | |
1088 | ||
1089 | my_offset = myh->root.u.def.value; | |
1090 | ||
1091 | s = bfd_get_section_by_name (bfd_of_glue_owner, | |
1092 | ARM2THUMB_GLUE_SECTION_NAME); | |
1093 | BFD_ASSERT (s != NULL); | |
1094 | BFD_ASSERT (s->contents != NULL); | |
1095 | ||
1096 | if ((my_offset & 0x01) == 0x01) | |
1097 | { | |
1098 | if (INTERWORK_SET (h_sec->owner) && ! INTERWORK_FLAG (h_sec->owner)) | |
1099 | _bfd_error_handler ("%s: warning: interworking not enabled.", | |
1100 | bfd_get_filename (h_sec->owner)); | |
1101 | ||
1102 | --my_offset; | |
1103 | myh->root.u.def.value = my_offset; | |
1104 | ||
1105 | bfd_put_32 (output_bfd, a2t1_ldr_insn, s->contents + my_offset); | |
1106 | ||
1107 | bfd_put_32 (output_bfd, a2t2_bx_r12_insn, s->contents + my_offset + 4); | |
1108 | ||
1109 | /* It's a thumb address. Add the low order bit. */ | |
1110 | bfd_put_32 (output_bfd, h_val | a2t3_func_addr_insn, s->contents + my_offset + 8); | |
1111 | } | |
1112 | ||
1113 | BFD_ASSERT (my_offset <= global_arm_glue_size); | |
1114 | ||
1115 | tmp = bfd_get_32 (input_bfd, contents + rel->r_vaddr - input_section->vma); | |
1116 | ||
1117 | tmp = tmp & 0xFF000000; | |
1118 | ||
1119 | /* Somehow these are both 4 too far, so subtract 8. */ | |
1120 | ret_offset = | |
1121 | s->output_offset | |
1122 | + my_offset | |
1123 | + s->output_section->vma | |
1124 | - (input_section->output_offset | |
1125 | + input_section->output_section->vma | |
1126 | + rel->r_vaddr) | |
1127 | - 8; | |
1128 | ||
1129 | tmp = tmp | ((ret_offset >> 2) & 0x00FFFFFF); | |
1130 | ||
1131 | bfd_put_32 (output_bfd, tmp, contents + rel->r_vaddr - input_section->vma); | |
1132 | ||
1133 | done = 1; | |
1134 | } | |
1135 | } | |
1136 | ||
1137 | /* Note: We used to check for ARM_THUMB9 and ARM_THUMB12 */ | |
1138 | else if (howto->type == ARM_THUMB23) | |
1139 | { | |
1140 | if ( h->class == C_EXT | |
1141 | || h->class == C_STAT | |
1142 | || h->class == C_LABEL) | |
1143 | { | |
1144 | /* Thumb code calling an ARM function */ | |
1145 | unsigned long int return_address; | |
1146 | signed long int final_disp; | |
1147 | asection * s = 0; | |
1148 | long int my_offset; | |
1149 | unsigned long int tmp; | |
1150 | long int ret_offset; | |
1151 | struct coff_link_hash_entry * myh; | |
1152 | ||
1153 | myh = find_thumb_glue (info, name, input_bfd); | |
1154 | if (myh == NULL) | |
1155 | return false; | |
1156 | ||
1157 | my_offset = myh->root.u.def.value; | |
1158 | ||
1159 | s = bfd_get_section_by_name (bfd_of_glue_owner, | |
1160 | THUMB2ARM_GLUE_SECTION_NAME); | |
1161 | ||
1162 | BFD_ASSERT (s != NULL); | |
1163 | BFD_ASSERT (s->contents != NULL); | |
1164 | ||
1165 | if ((my_offset & 0x01) == 0x01) | |
1166 | { | |
1167 | if (INTERWORK_SET (h_sec->owner) && ! INTERWORK_FLAG (h_sec->owner)) | |
1168 | _bfd_error_handler ("%s: warning: interworking not enabled.", | |
1169 | bfd_get_filename (h_sec->owner)); | |
1170 | ||
1171 | -- my_offset; | |
1172 | myh->root.u.def.value = my_offset; | |
1173 | ||
1174 | bfd_put_16 (output_bfd, t2a1_bx_pc_insn, | |
1175 | s->contents + my_offset); | |
1176 | ||
1177 | bfd_put_16 (output_bfd, t2a2_noop_insn, | |
1178 | s->contents + my_offset + 2); | |
1179 | ||
1180 | ret_offset = | |
1181 | ((signed)h_val) - | |
1182 | ((signed)(s->output_offset | |
1183 | + my_offset | |
1184 | + s->output_section->vma)) | |
1185 | - 12; | |
1186 | ||
1187 | t2a3_b_insn |= ((ret_offset >> 2) & 0x00FFFFFF); | |
1188 | ||
1189 | bfd_put_32 (output_bfd, t2a3_b_insn, s->contents + my_offset + 4); | |
1190 | } | |
1191 | ||
1192 | BFD_ASSERT (my_offset <= global_thumb_glue_size); | |
1193 | ||
1194 | /* Now go back and fix up the original bl insn to point here. */ | |
1195 | ret_offset = | |
1196 | s->output_offset | |
1197 | + my_offset | |
1198 | - (input_section->output_offset | |
1199 | + rel->r_vaddr) | |
1200 | -4; | |
1201 | ||
1202 | tmp = bfd_get_32 (input_bfd, contents + rel->r_vaddr - input_section->vma); | |
1203 | ||
1204 | bfd_put_32 (output_bfd, | |
1205 | insert_thumb_branch (tmp, ret_offset), | |
1206 | contents + rel->r_vaddr - input_section->vma); | |
1207 | ||
1208 | done = 1; | |
1209 | } | |
1210 | } | |
1211 | } | |
1212 | ||
1213 | /* If the relocation type and destination symbol does not | |
1214 | fall into one of the above categories, then we can just | |
1215 | perform a direct link. */ | |
1216 | ||
1217 | if (done) | |
1218 | rstat = bfd_reloc_ok; | |
1219 | else | |
1220 | #endif /* THUMBEXTENSION */ | |
1221 | if ( h->root.type == bfd_link_hash_defined | |
1222 | || h->root.type == bfd_link_hash_defweak) | |
1223 | { | |
1224 | asection *sec; | |
1225 | ||
1226 | sec = h->root.u.def.section; | |
1227 | val = (h->root.u.def.value | |
1228 | + sec->output_section->vma | |
1229 | + sec->output_offset); | |
1230 | } | |
1231 | ||
1232 | else if (! info->relocateable) | |
1233 | { | |
1234 | if (! ((*info->callbacks->undefined_symbol) | |
1235 | (info, h->root.root.string, input_bfd, input_section, | |
1236 | rel->r_vaddr - input_section->vma))) | |
1237 | return false; | |
1238 | } | |
1239 | } | |
1240 | ||
1241 | if (info->base_file) | |
1242 | { | |
1243 | /* Emit a reloc if the backend thinks it needs it. */ | |
1244 | if (sym && pe_data(output_bfd)->in_reloc_p(output_bfd, howto)) | |
1245 | { | |
1246 | /* relocation to a symbol in a section which | |
1247 | isn't absolute - we output the address here | |
1248 | to a file */ | |
1249 | bfd_vma addr = rel->r_vaddr | |
1250 | - input_section->vma | |
1251 | + input_section->output_offset | |
1252 | + input_section->output_section->vma; | |
1253 | if (coff_data(output_bfd)->pe) | |
1254 | addr -= pe_data(output_bfd)->pe_opthdr.ImageBase; | |
1255 | /* FIXME: Shouldn't 4 be sizeof (addr)? */ | |
1256 | fwrite (&addr, 1,4, (FILE *) info->base_file); | |
1257 | } | |
1258 | } | |
1259 | ||
1260 | #if 1 /* THUMBEXTENSION */ | |
1261 | if (done) | |
1262 | ; | |
1263 | /* Only perform this fix during the final link, not a relocatable link. nickc@cygnus.com */ | |
1264 | else if (! info->relocateable | |
1265 | && howto->type == ARM_THUMB23) | |
1266 | { | |
1267 | /* This is pretty much a copy of what the default | |
1268 | _bfd_final_link_relocate and _bfd_relocate_contents | |
1269 | routines do to perform a relocation, with special | |
1270 | processing for the split addressing of the Thumb BL | |
1271 | instruction. Again, it would probably be simpler adding a | |
1272 | ThumbBRANCH23 specific macro expansion into the default | |
1273 | code. */ | |
1274 | ||
1275 | bfd_vma address = rel->r_vaddr - input_section->vma; | |
1276 | ||
1277 | if (address > input_section->_raw_size) | |
1278 | rstat = bfd_reloc_outofrange; | |
1279 | else | |
1280 | { | |
1281 | bfd_vma relocation = val + addend; | |
1282 | int size = bfd_get_reloc_size (howto); | |
1283 | boolean overflow = false; | |
1284 | bfd_byte * location = contents + address; | |
1285 | bfd_vma x = bfd_get_32 (input_bfd, location); | |
1286 | bfd_vma src_mask = 0x007FFFFE; | |
1287 | bfd_signed_vma reloc_signed_max = (1 << (howto->bitsize - 1)) - 1; | |
1288 | bfd_signed_vma reloc_signed_min = ~reloc_signed_max; | |
1289 | bfd_vma check; | |
1290 | bfd_signed_vma signed_check; | |
1291 | bfd_vma add; | |
1292 | bfd_signed_vma signed_add; | |
1293 | ||
1294 | BFD_ASSERT (size == 4); | |
1295 | ||
1296 | /* howto->pc_relative should be TRUE for type 14 BRANCH23 */ | |
1297 | relocation -= (input_section->output_section->vma | |
1298 | + input_section->output_offset); | |
1299 | ||
1300 | /* howto->pcrel_offset should be TRUE for type 14 BRANCH23 */ | |
1301 | relocation -= address; | |
1302 | ||
1303 | /* No need to negate the relocation with BRANCH23. */ | |
1304 | /* howto->complain_on_overflow == complain_overflow_signed for BRANCH23. */ | |
1305 | /* howto->rightshift == 1 */ | |
1306 | /* Drop unwanted bits from the value we are relocating to. */ | |
1307 | ||
1308 | check = relocation >> howto->rightshift; | |
1309 | ||
1310 | /* If this is a signed value, the rightshift just dropped | |
1311 | leading 1 bits (assuming twos complement). */ | |
1312 | if ((bfd_signed_vma) relocation >= 0) | |
1313 | signed_check = check; | |
1314 | else | |
1315 | signed_check = (check | |
1316 | | ((bfd_vma) - 1 | |
1317 | & ~((bfd_vma) - 1 >> howto->rightshift))); | |
1318 | ||
1319 | /* Get the value from the object file. */ | |
1320 | if (bfd_big_endian (input_bfd)) | |
1321 | { | |
1322 | add = (((x) & 0x07ff0000) >> 4) | (((x) & 0x7ff) << 1); | |
1323 | } | |
1324 | else | |
1325 | { | |
1326 | add = ((((x) & 0x7ff) << 12) | (((x) & 0x07ff0000) >> 15)); | |
1327 | } | |
1328 | ||
1329 | /* Get the value from the object file with an appropriate sign. | |
1330 | The expression involving howto->src_mask isolates the upper | |
1331 | bit of src_mask. If that bit is set in the value we are | |
1332 | adding, it is negative, and we subtract out that number times | |
1333 | two. If src_mask includes the highest possible bit, then we | |
1334 | can not get the upper bit, but that does not matter since | |
1335 | signed_add needs no adjustment to become negative in that | |
1336 | case. */ | |
1337 | ||
1338 | signed_add = add; | |
1339 | ||
1340 | if ((add & (((~ src_mask) >> 1) & src_mask)) != 0) | |
1341 | signed_add -= (((~ src_mask) >> 1) & src_mask) << 1; | |
1342 | ||
1343 | /* Add the value from the object file, shifted so that it is a | |
1344 | straight number. */ | |
1345 | /* howto->bitpos == 0 */ | |
1346 | ||
1347 | signed_check += signed_add; | |
1348 | relocation += signed_add; | |
1349 | ||
1350 | BFD_ASSERT (howto->complain_on_overflow == complain_overflow_signed); | |
1351 | ||
1352 | /* Assumes two's complement. */ | |
1353 | if ( signed_check > reloc_signed_max | |
1354 | || signed_check < reloc_signed_min) | |
1355 | overflow = true; | |
1356 | ||
1357 | /* Put RELOCATION into the correct bits: */ | |
1358 | ||
1359 | if (bfd_big_endian (input_bfd)) | |
1360 | { | |
1361 | relocation = (((relocation & 0xffe) >> 1) | ((relocation << 4) & 0x07ff0000)); | |
1362 | } | |
1363 | else | |
1364 | { | |
1365 | relocation = (((relocation & 0xffe) << 15) | ((relocation >> 12) & 0x7ff)); | |
1366 | } | |
1367 | ||
1368 | /* Add RELOCATION to the correct bits of X: */ | |
1369 | x = ((x & ~howto->dst_mask) | relocation); | |
1370 | ||
1371 | /* Put the relocated value back in the object file: */ | |
1372 | bfd_put_32 (input_bfd, x, location); | |
1373 | ||
1374 | rstat = overflow ? bfd_reloc_overflow : bfd_reloc_ok; | |
1375 | } | |
1376 | } | |
1377 | else | |
1378 | #endif /* THUMBEXTENSION */ | |
1379 | rstat = _bfd_final_link_relocate (howto, input_bfd, input_section, | |
1380 | contents, | |
1381 | rel->r_vaddr - input_section->vma, | |
1382 | val, addend); | |
1383 | #if 1 /* THUMBEXTENSION */ | |
1384 | /* FIXME: | |
1385 | Is this the best way to fix up thumb addresses? krk@cygnus.com | |
1386 | Probably not, but it works, and if it works it don't need fixing! nickc@cygnus.com */ | |
1387 | /* Only perform this fix during the final link, not a relocatable link. nickc@cygnus.com */ | |
1388 | if (! info->relocateable | |
1389 | && rel->r_type == ARM_32) | |
1390 | { | |
1391 | /* Determine if we need to set the bottom bit of a relocated address | |
1392 | because the address is the address of a Thumb code symbol. */ | |
1393 | ||
1394 | int patchit = false; | |
1395 | ||
1396 | if (h != NULL | |
1397 | && ( h->class == C_THUMBSTATFUNC | |
1398 | || h->class == C_THUMBEXTFUNC)) | |
1399 | { | |
1400 | patchit = true; | |
1401 | } | |
1402 | else if (sym != NULL | |
1403 | && sym->n_scnum > N_UNDEF) | |
1404 | { | |
1405 | /* No hash entry - use the symbol instead. */ | |
1406 | ||
1407 | if ( sym->n_sclass == C_THUMBSTATFUNC | |
1408 | || sym->n_sclass == C_THUMBEXTFUNC) | |
1409 | patchit = true; | |
1410 | } | |
1411 | ||
1412 | if (patchit) | |
1413 | { | |
1414 | bfd_byte * location = contents + rel->r_vaddr - input_section->vma; | |
1415 | bfd_vma x = bfd_get_32 (input_bfd, location); | |
1416 | ||
1417 | bfd_put_32 (input_bfd, x | 1, location); | |
1418 | } | |
1419 | } | |
1420 | #endif /* THUMBEXTENSION */ | |
1421 | ||
1422 | switch (rstat) | |
1423 | { | |
1424 | default: | |
1425 | abort (); | |
1426 | case bfd_reloc_ok: | |
1427 | break; | |
1428 | case bfd_reloc_outofrange: | |
1429 | (*_bfd_error_handler) | |
1430 | ("%s: bad reloc address 0x%lx in section `%s'", | |
1431 | bfd_get_filename (input_bfd), | |
1432 | (unsigned long) rel->r_vaddr, | |
1433 | bfd_get_section_name (input_bfd, input_section)); | |
1434 | return false; | |
1435 | case bfd_reloc_overflow: | |
1436 | { | |
1437 | const char *name; | |
1438 | char buf[SYMNMLEN + 1]; | |
1439 | ||
1440 | if (symndx == -1) | |
1441 | name = "*ABS*"; | |
1442 | else if (h != NULL) | |
1443 | name = h->root.root.string; | |
1444 | else | |
1445 | { | |
1446 | name = _bfd_coff_internal_syment_name (input_bfd, sym, buf); | |
1447 | if (name == NULL) | |
1448 | return false; | |
1449 | } | |
1450 | ||
1451 | if (! ((*info->callbacks->reloc_overflow) | |
1452 | (info, name, howto->name, (bfd_vma) 0, input_bfd, | |
1453 | input_section, rel->r_vaddr - input_section->vma))) | |
1454 | return false; | |
1455 | } | |
1456 | } | |
1457 | } | |
1458 | ||
1459 | return true; | |
1460 | } | |
1461 | ||
1462 | boolean | |
1463 | arm_allocate_interworking_sections (info) | |
1464 | struct bfd_link_info *info; | |
1465 | { | |
1466 | asection *s; | |
1467 | bfd_byte *foo; | |
1468 | static char test_char = '1'; | |
1469 | ||
1470 | if ( global_arm_glue_size != 0 ) | |
1471 | { | |
1472 | BFD_ASSERT (bfd_of_glue_owner != NULL); | |
1473 | ||
1474 | s = bfd_get_section_by_name (bfd_of_glue_owner, ARM2THUMB_GLUE_SECTION_NAME); | |
1475 | ||
1476 | BFD_ASSERT (s != NULL); | |
1477 | ||
1478 | foo = (bfd_byte *) bfd_alloc(bfd_of_glue_owner, global_arm_glue_size); | |
1479 | memset(foo, test_char, global_arm_glue_size); | |
1480 | ||
1481 | s->_raw_size = s->_cooked_size = global_arm_glue_size; | |
1482 | s->contents = foo; | |
1483 | } | |
1484 | ||
1485 | if (global_thumb_glue_size != 0) | |
1486 | { | |
1487 | BFD_ASSERT (bfd_of_glue_owner != NULL); | |
1488 | ||
1489 | s = bfd_get_section_by_name (bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME); | |
1490 | ||
1491 | BFD_ASSERT (s != NULL); | |
1492 | ||
1493 | foo = (bfd_byte *) bfd_alloc(bfd_of_glue_owner, global_thumb_glue_size); | |
1494 | memset(foo, test_char, global_thumb_glue_size); | |
1495 | ||
1496 | s->_raw_size = s->_cooked_size = global_thumb_glue_size; | |
1497 | s->contents = foo; | |
1498 | } | |
1499 | ||
1500 | return true; | |
1501 | } | |
1502 | ||
1503 | static void | |
1504 | record_arm_to_thumb_glue (info, h) | |
1505 | struct bfd_link_info * info; | |
1506 | struct coff_link_hash_entry * h; | |
1507 | { | |
1508 | const char * name = h->root.root.string; | |
1509 | register asection * s; | |
1510 | char * tmp_name; | |
1511 | struct coff_link_hash_entry * myh; | |
1512 | ||
1513 | ||
1514 | BFD_ASSERT (bfd_of_glue_owner != NULL); | |
1515 | ||
1516 | s = bfd_get_section_by_name (bfd_of_glue_owner, | |
1517 | ARM2THUMB_GLUE_SECTION_NAME); | |
1518 | ||
1519 | BFD_ASSERT (s != NULL); | |
1520 | ||
1521 | tmp_name = ((char *) | |
1522 | bfd_malloc (strlen (name) + strlen (ARM2THUMB_GLUE_ENTRY_NAME))); | |
1523 | ||
1524 | BFD_ASSERT (tmp_name); | |
1525 | ||
1526 | sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name); | |
1527 | ||
1528 | myh = coff_link_hash_lookup (coff_hash_table (info), | |
1529 | tmp_name, | |
1530 | false, false, true); | |
1531 | ||
1532 | if (myh != NULL) | |
1533 | { | |
1534 | free (tmp_name); | |
1535 | return; /* we've already seen this guy */ | |
1536 | } | |
1537 | ||
1538 | ||
1539 | /* The only trick here is using global_arm_glue_size as the value. Even | |
1540 | though the section isn't allocated yet, this is where we will be putting | |
1541 | it. */ | |
1542 | ||
1543 | bfd_coff_link_add_one_symbol (info, bfd_of_glue_owner, tmp_name, | |
1544 | BSF_EXPORT | BSF_GLOBAL, | |
1545 | s, global_arm_glue_size + 1, | |
1546 | NULL, true, false, | |
1547 | (struct bfd_link_hash_entry **) & myh); | |
1548 | ||
1549 | global_arm_glue_size += ARM2THUMB_GLUE_SIZE; | |
1550 | ||
1551 | free (tmp_name); | |
1552 | ||
1553 | return; | |
1554 | } | |
1555 | ||
1556 | static void | |
1557 | record_thumb_to_arm_glue (info, h) | |
1558 | struct bfd_link_info * info; | |
1559 | struct coff_link_hash_entry * h; | |
1560 | { | |
1561 | const char * name = h->root.root.string; | |
1562 | register asection * s; | |
1563 | char * tmp_name; | |
1564 | struct coff_link_hash_entry * myh; | |
1565 | ||
1566 | ||
1567 | BFD_ASSERT (bfd_of_glue_owner != NULL); | |
1568 | ||
1569 | s = bfd_get_section_by_name (bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME); | |
1570 | ||
1571 | BFD_ASSERT (s != NULL); | |
1572 | ||
1573 | tmp_name = (char *) bfd_malloc (strlen (name) + strlen (THUMB2ARM_GLUE_ENTRY_NAME)); | |
1574 | ||
1575 | BFD_ASSERT (tmp_name); | |
1576 | ||
1577 | sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name); | |
1578 | ||
1579 | myh = coff_link_hash_lookup (coff_hash_table (info), | |
1580 | tmp_name, | |
1581 | false, false, true); | |
1582 | ||
1583 | if (myh != NULL) | |
1584 | { | |
1585 | free (tmp_name); | |
1586 | return; /* we've already seen this guy */ | |
1587 | } | |
1588 | ||
1589 | bfd_coff_link_add_one_symbol (info, bfd_of_glue_owner, tmp_name, | |
1590 | BSF_LOCAL, s, global_thumb_glue_size + 1, | |
1591 | NULL, true, false, | |
1592 | (struct bfd_link_hash_entry **) & myh); | |
1593 | ||
1594 | /* if we mark it 'thumb', the disassembler will do a better job */ | |
1595 | myh->class = C_THUMBEXTFUNC; | |
1596 | ||
1597 | free (tmp_name); | |
1598 | ||
1599 | #define CHANGE_TO_ARM "__%s_change_to_arm" | |
1600 | ||
1601 | tmp_name = ((char *) | |
1602 | bfd_malloc (strlen (name) + strlen (CHANGE_TO_ARM))); | |
1603 | ||
1604 | BFD_ASSERT (tmp_name); | |
1605 | ||
1606 | sprintf (tmp_name, CHANGE_TO_ARM, name); | |
1607 | ||
1608 | myh = NULL; | |
1609 | ||
1610 | /* now allocate another symbol to switch back to arm mode */ | |
1611 | bfd_coff_link_add_one_symbol (info, bfd_of_glue_owner, tmp_name, | |
1612 | BSF_LOCAL, s, global_thumb_glue_size + 4, | |
1613 | NULL, true, false, | |
1614 | (struct bfd_link_hash_entry **) & myh); | |
1615 | ||
1616 | free (tmp_name); | |
1617 | ||
1618 | global_thumb_glue_size += THUMB2ARM_GLUE_SIZE; | |
1619 | ||
1620 | return; | |
1621 | } | |
1622 | ||
1623 | boolean | |
1624 | arm_process_before_allocation (abfd, info) | |
1625 | bfd * abfd; | |
1626 | struct bfd_link_info * info; | |
1627 | { | |
1628 | asection * sec; | |
1629 | ||
1630 | /* If we are only performing a partial link do not bother | |
1631 | to construct any glue. */ | |
1632 | if (info->relocateable) | |
1633 | return true; | |
1634 | ||
1635 | /* Here we have a bfd that is to be included on the link. We have a hook | |
1636 | to do reloc rummaging, before section sizes are nailed down. */ | |
1637 | ||
1638 | _bfd_coff_get_external_symbols (abfd); | |
1639 | ||
1640 | /* Rummage around all the relocs and map the glue vectors. */ | |
1641 | sec = abfd->sections; | |
1642 | ||
1643 | if (sec == NULL) | |
1644 | return true; | |
1645 | ||
1646 | for (; sec != NULL; sec = sec->next) | |
1647 | { | |
1648 | struct internal_reloc * i; | |
1649 | struct internal_reloc * rel; | |
1650 | ||
1651 | if (sec->reloc_count == 0) | |
1652 | continue; | |
1653 | ||
1654 | /* Load the relocs. */ | |
1655 | /* FIXME: there may be a storage leak here. */ | |
1656 | ||
1657 | i = _bfd_coff_read_internal_relocs (abfd, sec, 1, 0, 0, 0); | |
1658 | ||
1659 | BFD_ASSERT (i != 0); | |
1660 | ||
1661 | for (rel = i; rel < i + sec->reloc_count; ++rel) | |
1662 | { | |
1663 | unsigned short r_type = rel->r_type; | |
1664 | long symndx; | |
1665 | struct coff_link_hash_entry * h; | |
1666 | ||
1667 | symndx = rel->r_symndx; | |
1668 | ||
1669 | /* If the relocation is not against a symbol it cannot concern us. */ | |
1670 | if (symndx == -1) | |
1671 | continue; | |
1672 | ||
1673 | h = obj_coff_sym_hashes (abfd)[symndx]; | |
1674 | ||
1675 | /* If the relocation is against a static symbol it must be within | |
1676 | the current section and so canot be a cross ARM/Thumb relocation. */ | |
1677 | if (h == NULL) | |
1678 | continue; | |
1679 | ||
1680 | switch (r_type) | |
1681 | { | |
1682 | case ARM_26: | |
1683 | /* This one is a call from arm code. We need to look up | |
1684 | the target of the call. If it is a thumb target, we | |
1685 | insert glue. */ | |
1686 | ||
1687 | if (h->class == C_THUMBEXTFUNC) | |
1688 | { | |
1689 | record_arm_to_thumb_glue (info, h); | |
1690 | } | |
1691 | break; | |
1692 | ||
1693 | case ARM_THUMB23: | |
1694 | /* This one is a call from thumb code. We used to look | |
1695 | for ARM_THUMB9 and ARM_THUMB12 as well. We need to look | |
1696 | up the target of the call. If it is an arm target, we | |
1697 | insert glue. */ | |
1698 | ||
1699 | switch (h->class) | |
1700 | { | |
1701 | case C_EXT: | |
1702 | case C_STAT: | |
1703 | case C_LABEL: | |
1704 | record_thumb_to_arm_glue (info, h); | |
1705 | break; | |
1706 | default: | |
1707 | ; | |
1708 | } | |
1709 | break; | |
1710 | ||
1711 | default: | |
1712 | break; | |
1713 | } | |
1714 | } | |
1715 | } | |
1716 | ||
1717 | return true; | |
1718 | } | |
1719 | ||
1720 | #define coff_relocate_section coff_arm_relocate_section | |
1721 | ||
1722 | /* When doing a relocateable link, we want to convert ARM26 relocs | |
1723 | into ARM26D relocs. */ | |
1724 | ||
1725 | static boolean | |
1726 | coff_arm_adjust_symndx (obfd, info, ibfd, sec, irel, adjustedp) | |
1727 | bfd *obfd; | |
1728 | struct bfd_link_info *info; | |
1729 | bfd *ibfd; | |
1730 | asection *sec; | |
1731 | struct internal_reloc *irel; | |
1732 | boolean *adjustedp; | |
1733 | { | |
1734 | if (irel->r_type == 3) | |
1735 | { | |
1736 | struct coff_link_hash_entry *h; | |
1737 | ||
1738 | h = obj_coff_sym_hashes (ibfd)[irel->r_symndx]; | |
1739 | if (h != NULL | |
1740 | && (h->root.type == bfd_link_hash_defined | |
1741 | || h->root.type == bfd_link_hash_defweak) | |
1742 | && h->root.u.def.section->output_section == sec->output_section) | |
1743 | irel->r_type = 7; | |
1744 | } | |
1745 | *adjustedp = false; | |
1746 | return true; | |
1747 | } | |
1748 | ||
1749 | ||
1750 | /* Called when merging the private data areas of two BFDs. | |
1751 | This is important as it allows us to detect if we are | |
1752 | attempting to merge binaries compiled for different ARM | |
1753 | targets, eg different CPUs or differents APCS's. */ | |
1754 | ||
1755 | static boolean | |
1756 | coff_arm_bfd_merge_private_bfd_data (ibfd, obfd) | |
1757 | bfd * ibfd; | |
1758 | bfd * obfd; | |
1759 | { | |
1760 | BFD_ASSERT (ibfd != NULL && obfd != NULL); | |
1761 | ||
1762 | if (ibfd == obfd) | |
1763 | return true; | |
1764 | ||
1765 | /* If the two formats are different we cannot merge anything. */ | |
1766 | if (ibfd->xvec != obfd->xvec) | |
1767 | { | |
1768 | bfd_set_error (bfd_error_wrong_format); | |
1769 | return false; | |
1770 | } | |
1771 | ||
1772 | /* Verify that the APCS is the same for the two BFDs */ | |
1773 | if (APCS_SET (ibfd)) | |
1774 | { | |
1775 | if (APCS_SET (obfd)) | |
1776 | { | |
1777 | /* If the src and dest have different APCS flag bits set, fail. */ | |
1778 | if (APCS_26_FLAG (obfd) != APCS_26_FLAG (ibfd)) | |
1779 | { | |
1780 | _bfd_error_handler | |
1781 | ("%s: ERROR: compiled for APCS-%d whereas target %s uses APCS-%d", | |
1782 | bfd_get_filename (ibfd), APCS_26_FLAG (ibfd) ? 26 : 32, | |
1783 | bfd_get_filename (obfd), APCS_26_FLAG (obfd) ? 26 : 32 | |
1784 | ); | |
1785 | ||
1786 | bfd_set_error (bfd_error_wrong_format); | |
1787 | return false; | |
1788 | } | |
1789 | ||
1790 | if (APCS_FLOAT_FLAG (obfd) != APCS_FLOAT_FLAG (ibfd)) | |
1791 | { | |
1792 | _bfd_error_handler | |
1793 | ("%s: ERROR: passes floats in %s registers whereas target %s uses %s registers", | |
1794 | bfd_get_filename (ibfd), APCS_FLOAT_FLAG (ibfd) ? "float" : "integer", | |
1795 | bfd_get_filename (obfd), APCS_FLOAT_FLAG (obfd) ? "float" : "integer" | |
1796 | ); | |
1797 | ||
1798 | bfd_set_error (bfd_error_wrong_format); | |
1799 | return false; | |
1800 | } | |
1801 | ||
1802 | if (PIC_FLAG (obfd) != PIC_FLAG (ibfd)) | |
1803 | { | |
1804 | _bfd_error_handler | |
1805 | ("%s: ERROR: compiled as %s code, whereas target %s is %s", | |
1806 | bfd_get_filename (ibfd), PIC_FLAG (ibfd) ? "position independent" : "absoluste position", | |
1807 | bfd_get_filename (obfd), PIC_FLAG (obfd) ? "position independent" : "absoluste position" | |
1808 | ); | |
1809 | ||
1810 | bfd_set_error (bfd_error_wrong_format); | |
1811 | return false; | |
1812 | } | |
1813 | } | |
1814 | else | |
1815 | { | |
1816 | SET_APCS_FLAGS (obfd, APCS_26_FLAG (ibfd) | APCS_FLOAT_FLAG (ibfd) | PIC_FLAG (ibfd)); | |
1817 | ||
1818 | /* Set up the arch and fields as well as these are probably wrong. */ | |
1819 | bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd)); | |
1820 | } | |
1821 | } | |
1822 | ||
1823 | /* Check the interworking support. */ | |
1824 | if (INTERWORK_SET (ibfd)) | |
1825 | { | |
1826 | if (INTERWORK_SET (obfd)) | |
1827 | { | |
1828 | /* If the src and dest differ in their interworking issue a warning. */ | |
1829 | if (INTERWORK_FLAG (obfd) != INTERWORK_FLAG (ibfd)) | |
1830 | { | |
1831 | _bfd_error_handler | |
1832 | ("Warning: input file %s %s interworking, whereas %s does%s", | |
1833 | bfd_get_filename (ibfd), | |
1834 | INTERWORK_FLAG (ibfd) ? "supports" : "does not support", | |
1835 | bfd_get_filename (obfd), | |
1836 | INTERWORK_FLAG (obfd) ? "." : " not." | |
1837 | ); | |
1838 | } | |
1839 | } | |
1840 | else | |
1841 | { | |
1842 | SET_INTERWORK_FLAG (obfd, INTERWORK_FLAG (ibfd)); | |
1843 | } | |
1844 | } | |
1845 | ||
1846 | return true; | |
1847 | } | |
1848 | ||
1849 | ||
1850 | /* Display the flags field */ | |
1851 | ||
1852 | static boolean | |
1853 | coff_arm_bfd_print_private_bfd_data (abfd, ptr) | |
1854 | bfd * abfd; | |
1855 | PTR ptr; | |
1856 | { | |
1857 | FILE * file = (FILE *) ptr; | |
1858 | ||
1859 | BFD_ASSERT (abfd != NULL && ptr != NULL) | |
1860 | ||
1861 | fprintf (file, "private flags = %x", coff_data( abfd )->flags); | |
1862 | ||
1863 | if (APCS_SET (abfd)) | |
1864 | fprintf (file, ": [APCS-%d] [floats passed in %s registers] [%s]", | |
1865 | APCS_26_FLAG (abfd) ? 26 : 32, | |
1866 | APCS_FLOAT_FLAG (abfd) ? "float" : "integer", | |
1867 | PIC_FLAG (abfd) ? "position independent" : "absolute position" | |
1868 | ); | |
1869 | ||
1870 | if (INTERWORK_SET (abfd)) | |
1871 | fprintf (file, ": [interworking %ssupported]", | |
1872 | INTERWORK_FLAG (abfd) ? "" : "not " ); | |
1873 | ||
1874 | fputc ('\n', file); | |
1875 | ||
1876 | return true; | |
1877 | } | |
1878 | ||
1879 | ||
1880 | /* Copies the given flags into the coff_tdata.flags field. | |
1881 | Typically these flags come from the f_flags[] field of | |
1882 | the COFF filehdr structure, which contains important, | |
1883 | target specific information. */ | |
1884 | ||
1885 | static boolean | |
1886 | coff_arm_bfd_set_private_flags (abfd, flags) | |
1887 | bfd * abfd; | |
1888 | flagword flags; | |
1889 | { | |
1890 | int flag; | |
1891 | ||
1892 | BFD_ASSERT (abfd != NULL); | |
1893 | ||
1894 | flag = (flags & F_APCS26) ? F_APCS_26 : 0; | |
1895 | ||
1896 | /* Make sure that the APCS field has not been initialised to the opposite value. */ | |
1897 | if (APCS_SET (abfd) | |
1898 | && ( (APCS_26_FLAG (abfd) != flag) | |
1899 | || (APCS_FLOAT_FLAG (abfd) != (flags & F_APCS_FLOAT)) | |
1900 | || (PIC_FLAG (abfd) != (flags & F_PIC)) | |
1901 | )) | |
1902 | return false; | |
1903 | ||
1904 | flag |= (flags & (F_APCS_FLOAT | F_PIC)); | |
1905 | ||
1906 | SET_APCS_FLAGS (abfd, flag); | |
1907 | ||
1908 | flag = (flags & F_INTERWORK); | |
1909 | ||
1910 | /* If either the flags or the BFD do support interworking then do not set the interworking flag. */ | |
1911 | if (INTERWORK_SET (abfd) && (INTERWORK_FLAG (abfd) != flag)) | |
1912 | flag = 0; | |
1913 | ||
1914 | SET_INTERWORK_FLAG (abfd, flag); | |
1915 | ||
1916 | return true; | |
1917 | } | |
1918 | ||
1919 | ||
1920 | /* Copy the important parts of the target specific data | |
1921 | from one instance of a BFD to another. */ | |
1922 | ||
1923 | static boolean | |
1924 | coff_arm_bfd_copy_private_bfd_data (src, dest) | |
1925 | bfd * src; | |
1926 | bfd * dest; | |
1927 | { | |
1928 | BFD_ASSERT (src != NULL && dest != NULL); | |
1929 | ||
1930 | if (src == dest) | |
1931 | return true; | |
1932 | ||
1933 | /* If the destination is not in the same format as the source, do not do the copy. */ | |
1934 | if (src->xvec != dest->xvec) | |
1935 | return true; | |
1936 | ||
1937 | /* copy the flags field */ | |
1938 | if (APCS_SET (src)) | |
1939 | { | |
1940 | if (APCS_SET (dest)) | |
1941 | { | |
1942 | /* If the src and dest have different APCS flag bits set, fail. */ | |
1943 | if (APCS_26_FLAG (dest) != APCS_26_FLAG (src)) | |
1944 | return false; | |
1945 | ||
1946 | if (APCS_FLOAT_FLAG (dest) != APCS_FLOAT_FLAG (src)) | |
1947 | return false; | |
1948 | ||
1949 | if (PIC_FLAG (dest) != PIC_FLAG (src)) | |
1950 | return false; | |
1951 | } | |
1952 | else | |
1953 | SET_APCS_FLAGS (dest, APCS_26_FLAG (src) | APCS_FLOAT_FLAG (src) | PIC_FLAG (src)); | |
1954 | } | |
1955 | ||
1956 | if (INTERWORK_SET (src)) | |
1957 | { | |
1958 | if (INTERWORK_SET (dest)) | |
1959 | { | |
1960 | /* If the src and dest have different interworking flags then turn off the interworking bit. */ | |
1961 | if (INTERWORK_FLAG (dest) != INTERWORK_FLAG (src)) | |
1962 | SET_INTERWORK_FLAG (dest, 0); | |
1963 | } | |
1964 | else | |
1965 | { | |
1966 | SET_INTERWORK_FLAG (dest, INTERWORK_FLAG (src)); | |
1967 | } | |
1968 | } | |
1969 | ||
1970 | return true; | |
1971 | } | |
1972 | ||
1973 | /* Note: the definitions here of LOCAL_LABEL_PREFIX and USER_LABEL_PREIFX | |
1974 | *must* match the definitions on gcc/config/arm/semi.h. */ | |
1975 | #define LOCAL_LABEL_PREFIX "." | |
1976 | #define USER_LABEL_PREFIX "_" | |
1977 | ||
1978 | static boolean | |
1979 | coff_arm_is_local_label_name (abfd, name) | |
1980 | bfd * abfd; | |
1981 | const char * name; | |
1982 | { | |
1983 | #ifdef LOCAL_LABEL_PREFIX | |
1984 | /* If there is a prefix for local labels then look for this. | |
1985 | If the prefix exists, but it is empty, then ignore the test. */ | |
1986 | ||
1987 | if (LOCAL_LABEL_PREFIX[0] != 0) | |
1988 | { | |
1989 | if (strncmp (name, LOCAL_LABEL_PREFIX, strlen (LOCAL_LABEL_PREFIX)) == 0) | |
1990 | return true; | |
1991 | } | |
1992 | #endif | |
1993 | #ifdef USER_LABEL_PREFIX | |
1994 | if (USER_LABEL_PREFIX[0] != 0) | |
1995 | { | |
1996 | if (strncmp (name, USER_LABEL_PREFIX, strlen (USER_LABEL_PREFIX)) == 0) | |
1997 | return false; | |
1998 | } | |
1999 | #endif | |
2000 | ||
2001 | /* devo/gcc/config/dbxcoff.h defines ASM_OUTPUT_SOURCE_LINE to generate local line numbers as .LM<number>, so treat these as local. */ | |
2002 | ||
2003 | switch (name[0]) | |
2004 | { | |
2005 | case 'L': return true; | |
2006 | case '.': return (name[1] == 'L' && name[2] == 'M') ? true : false; | |
2007 | default: return false; /* Cannot make our minds up - default to false so that it will not be stripped by accident. */ | |
2008 | } | |
2009 | } | |
2010 | ||
2011 | #define coff_bfd_is_local_label_name coff_arm_is_local_label_name | |
2012 | #define coff_adjust_symndx coff_arm_adjust_symndx | |
2013 | #define coff_bfd_final_link coff_arm_bfd_final_link | |
46686c78 NC |
2014 | #define coff_bfd_merge_private_bfd_data coff_arm_bfd_merge_private_bfd_data |
2015 | #define coff_bfd_print_private_bfd_data coff_arm_bfd_print_private_bfd_data | |
2016 | #define coff_bfd_set_private_flags coff_arm_bfd_set_private_flags | |
2017 | #define coff_bfd_copy_private_bfd_data coff_arm_bfd_copy_private_bfd_data | |
a5655244 | 2018 | |
943fbd5b KR |
2019 | #include "coffcode.h" |
2020 | ||
e1aeb285 NC |
2021 | static boolean |
2022 | arm_do_last (abfd) | |
2023 | bfd * abfd; | |
2024 | { | |
2025 | if (abfd == bfd_of_glue_owner) | |
2026 | return true; | |
2027 | else | |
2028 | return false; | |
2029 | } | |
2030 | ||
2031 | static bfd * | |
2032 | arm_get_last() | |
2033 | { | |
2034 | return bfd_of_glue_owner; | |
2035 | } | |
2036 | ||
2037 | /* This piece of machinery exists only to guarantee that the bfd that holds | |
2038 | the glue section is written last. | |
2039 | ||
2040 | This does depend on bfd_make_section attaching a new section to the | |
2041 | end of the section list for the bfd. | |
2042 | ||
2043 | This is otherwise intended to be functionally the same as | |
2044 | cofflink.c:_bfd_coff_final_link(). It is specifically different only | |
2045 | where the ARM_HACKS macro modifies the code. It is left in as a | |
2046 | precise form of comment. krk@cygnus.com */ | |
2047 | ||
2048 | #define ARM_HACKS | |
2049 | ||
2050 | ||
2051 | /* Do the final link step. */ | |
2052 | ||
2053 | boolean | |
2054 | coff_arm_bfd_final_link (abfd, info) | |
2055 | bfd *abfd; | |
2056 | struct bfd_link_info *info; | |
2057 | { | |
2058 | bfd_size_type symesz; | |
2059 | struct coff_final_link_info finfo; | |
2060 | boolean debug_merge_allocated; | |
2061 | asection *o; | |
2062 | struct bfd_link_order *p; | |
2063 | size_t max_sym_count; | |
2064 | size_t max_lineno_count; | |
2065 | size_t max_reloc_count; | |
2066 | size_t max_output_reloc_count; | |
2067 | size_t max_contents_size; | |
2068 | file_ptr rel_filepos; | |
2069 | unsigned int relsz; | |
2070 | file_ptr line_filepos; | |
2071 | unsigned int linesz; | |
2072 | bfd *sub; | |
2073 | bfd_byte *external_relocs = NULL; | |
2074 | char strbuf[STRING_SIZE_SIZE]; | |
2075 | ||
2076 | symesz = bfd_coff_symesz (abfd); | |
2077 | ||
2078 | finfo.info = info; | |
2079 | finfo.output_bfd = abfd; | |
2080 | finfo.strtab = NULL; | |
2081 | finfo.section_info = NULL; | |
2082 | finfo.last_file_index = -1; | |
2083 | finfo.last_bf_index = -1; | |
2084 | finfo.internal_syms = NULL; | |
2085 | finfo.sec_ptrs = NULL; | |
2086 | finfo.sym_indices = NULL; | |
2087 | finfo.outsyms = NULL; | |
2088 | finfo.linenos = NULL; | |
2089 | finfo.contents = NULL; | |
2090 | finfo.external_relocs = NULL; | |
2091 | finfo.internal_relocs = NULL; | |
2092 | debug_merge_allocated = false; | |
2093 | ||
2094 | coff_data (abfd)->link_info = info; | |
2095 | ||
2096 | finfo.strtab = _bfd_stringtab_init (); | |
2097 | if (finfo.strtab == NULL) | |
2098 | goto error_return; | |
2099 | ||
2100 | if (! coff_debug_merge_hash_table_init (&finfo.debug_merge)) | |
2101 | goto error_return; | |
2102 | debug_merge_allocated = true; | |
2103 | ||
2104 | /* Compute the file positions for all the sections. */ | |
2105 | if (! abfd->output_has_begun) | |
2106 | bfd_coff_compute_section_file_positions (abfd); | |
2107 | ||
2108 | /* Count the line numbers and relocation entries required for the | |
2109 | output file. Set the file positions for the relocs. */ | |
2110 | rel_filepos = obj_relocbase (abfd); | |
2111 | relsz = bfd_coff_relsz (abfd); | |
2112 | max_contents_size = 0; | |
2113 | max_lineno_count = 0; | |
2114 | max_reloc_count = 0; | |
2115 | ||
2116 | for (o = abfd->sections; o != NULL; o = o->next) | |
2117 | { | |
2118 | o->reloc_count = 0; | |
2119 | o->lineno_count = 0; | |
2120 | for (p = o->link_order_head; p != NULL; p = p->next) | |
2121 | { | |
2122 | ||
2123 | if (p->type == bfd_indirect_link_order) | |
2124 | { | |
2125 | asection *sec; | |
2126 | ||
2127 | sec = p->u.indirect.section; | |
2128 | ||
2129 | /* Mark all sections which are to be included in the | |
2130 | link. This will normally be every section. We need | |
2131 | to do this so that we can identify any sections which | |
2132 | the linker has decided to not include. */ | |
2133 | sec->linker_mark = true; | |
2134 | ||
2135 | if (info->strip == strip_none | |
2136 | || info->strip == strip_some) | |
2137 | o->lineno_count += sec->lineno_count; | |
2138 | ||
2139 | if (info->relocateable) | |
2140 | o->reloc_count += sec->reloc_count; | |
2141 | ||
2142 | if (sec->_raw_size > max_contents_size) | |
2143 | max_contents_size = sec->_raw_size; | |
2144 | if (sec->lineno_count > max_lineno_count) | |
2145 | max_lineno_count = sec->lineno_count; | |
2146 | if (sec->reloc_count > max_reloc_count) | |
2147 | max_reloc_count = sec->reloc_count; | |
2148 | } | |
2149 | else if (info->relocateable | |
2150 | && (p->type == bfd_section_reloc_link_order | |
2151 | || p->type == bfd_symbol_reloc_link_order)) | |
2152 | ++o->reloc_count; | |
2153 | } | |
2154 | if (o->reloc_count == 0) | |
2155 | o->rel_filepos = 0; | |
2156 | else | |
2157 | { | |
2158 | o->flags |= SEC_RELOC; | |
2159 | o->rel_filepos = rel_filepos; | |
2160 | rel_filepos += o->reloc_count * relsz; | |
2161 | } | |
2162 | } | |
2163 | ||
2164 | /* If doing a relocateable link, allocate space for the pointers we | |
2165 | need to keep. */ | |
2166 | if (info->relocateable) | |
2167 | { | |
2168 | unsigned int i; | |
2169 | ||
2170 | /* We use section_count + 1, rather than section_count, because | |
2171 | the target_index fields are 1 based. */ | |
2172 | finfo.section_info = | |
2173 | ((struct coff_link_section_info *) | |
2174 | bfd_malloc ((abfd->section_count + 1) | |
2175 | * sizeof (struct coff_link_section_info))); | |
2176 | if (finfo.section_info == NULL) | |
2177 | goto error_return; | |
2178 | for (i = 0; i <= abfd->section_count; i++) | |
2179 | { | |
2180 | finfo.section_info[i].relocs = NULL; | |
2181 | finfo.section_info[i].rel_hashes = NULL; | |
2182 | } | |
2183 | } | |
2184 | ||
2185 | /* We now know the size of the relocs, so we can determine the file | |
2186 | positions of the line numbers. */ | |
2187 | line_filepos = rel_filepos; | |
2188 | linesz = bfd_coff_linesz (abfd); | |
2189 | max_output_reloc_count = 0; | |
2190 | for (o = abfd->sections; o != NULL; o = o->next) | |
2191 | { | |
2192 | if (o->lineno_count == 0) | |
2193 | o->line_filepos = 0; | |
2194 | else | |
2195 | { | |
2196 | o->line_filepos = line_filepos; | |
2197 | line_filepos += o->lineno_count * linesz; | |
2198 | } | |
2199 | ||
2200 | if (o->reloc_count != 0) | |
2201 | { | |
2202 | /* We don't know the indices of global symbols until we have | |
2203 | written out all the local symbols. For each section in | |
2204 | the output file, we keep an array of pointers to hash | |
2205 | table entries. Each entry in the array corresponds to a | |
2206 | reloc. When we find a reloc against a global symbol, we | |
2207 | set the corresponding entry in this array so that we can | |
2208 | fix up the symbol index after we have written out all the | |
2209 | local symbols. | |
2210 | ||
2211 | Because of this problem, we also keep the relocs in | |
2212 | memory until the end of the link. This wastes memory, | |
2213 | but only when doing a relocateable link, which is not the | |
2214 | common case. */ | |
2215 | BFD_ASSERT (info->relocateable); | |
2216 | finfo.section_info[o->target_index].relocs = | |
2217 | ((struct internal_reloc *) | |
2218 | bfd_malloc (o->reloc_count * sizeof (struct internal_reloc))); | |
2219 | finfo.section_info[o->target_index].rel_hashes = | |
2220 | ((struct coff_link_hash_entry **) | |
2221 | bfd_malloc (o->reloc_count | |
2222 | * sizeof (struct coff_link_hash_entry *))); | |
2223 | if (finfo.section_info[o->target_index].relocs == NULL | |
2224 | || finfo.section_info[o->target_index].rel_hashes == NULL) | |
2225 | goto error_return; | |
2226 | ||
2227 | if (o->reloc_count > max_output_reloc_count) | |
2228 | max_output_reloc_count = o->reloc_count; | |
2229 | } | |
2230 | ||
2231 | /* Reset the reloc and lineno counts, so that we can use them to | |
2232 | count the number of entries we have output so far. */ | |
2233 | o->reloc_count = 0; | |
2234 | o->lineno_count = 0; | |
2235 | } | |
2236 | ||
2237 | obj_sym_filepos (abfd) = line_filepos; | |
2238 | ||
2239 | /* Figure out the largest number of symbols in an input BFD. Take | |
2240 | the opportunity to clear the output_has_begun fields of all the | |
2241 | input BFD's. */ | |
2242 | max_sym_count = 0; | |
2243 | for (sub = info->input_bfds; sub != NULL; sub = sub->link_next) | |
2244 | { | |
2245 | size_t sz; | |
2246 | ||
2247 | sub->output_has_begun = false; | |
2248 | sz = obj_raw_syment_count (sub); | |
2249 | if (sz > max_sym_count) | |
2250 | max_sym_count = sz; | |
2251 | } | |
2252 | ||
2253 | /* Allocate some buffers used while linking. */ | |
2254 | finfo.internal_syms = ((struct internal_syment *) | |
2255 | bfd_malloc (max_sym_count | |
2256 | * sizeof (struct internal_syment))); | |
2257 | finfo.sec_ptrs = (asection **) bfd_malloc (max_sym_count | |
2258 | * sizeof (asection *)); | |
2259 | finfo.sym_indices = (long *) bfd_malloc (max_sym_count * sizeof (long)); | |
2260 | finfo.outsyms = ((bfd_byte *) | |
2261 | bfd_malloc ((size_t) ((max_sym_count + 1) * symesz))); | |
2262 | finfo.linenos = (bfd_byte *) bfd_malloc (max_lineno_count | |
2263 | * bfd_coff_linesz (abfd)); | |
2264 | finfo.contents = (bfd_byte *) bfd_malloc (max_contents_size); | |
2265 | finfo.external_relocs = (bfd_byte *) bfd_malloc (max_reloc_count * relsz); | |
2266 | if (! info->relocateable) | |
2267 | finfo.internal_relocs = ((struct internal_reloc *) | |
2268 | bfd_malloc (max_reloc_count | |
2269 | * sizeof (struct internal_reloc))); | |
2270 | if ((finfo.internal_syms == NULL && max_sym_count > 0) | |
2271 | || (finfo.sec_ptrs == NULL && max_sym_count > 0) | |
2272 | || (finfo.sym_indices == NULL && max_sym_count > 0) | |
2273 | || finfo.outsyms == NULL | |
2274 | || (finfo.linenos == NULL && max_lineno_count > 0) | |
2275 | || (finfo.contents == NULL && max_contents_size > 0) | |
2276 | || (finfo.external_relocs == NULL && max_reloc_count > 0) | |
2277 | || (! info->relocateable | |
2278 | && finfo.internal_relocs == NULL | |
2279 | && max_reloc_count > 0)) | |
2280 | goto error_return; | |
2281 | ||
2282 | /* We now know the position of everything in the file, except that | |
2283 | we don't know the size of the symbol table and therefore we don't | |
2284 | know where the string table starts. We just build the string | |
2285 | table in memory as we go along. We process all the relocations | |
2286 | for a single input file at once. */ | |
2287 | obj_raw_syment_count (abfd) = 0; | |
2288 | ||
2289 | if (coff_backend_info (abfd)->_bfd_coff_start_final_link) | |
2290 | { | |
2291 | if (! bfd_coff_start_final_link (abfd, info)) | |
2292 | goto error_return; | |
2293 | } | |
2294 | ||
2295 | for (o = abfd->sections; o != NULL; o = o->next) | |
2296 | { | |
2297 | for (p = o->link_order_head; p != NULL; p = p->next) | |
2298 | { | |
2299 | if (p->type == bfd_indirect_link_order | |
2300 | && (bfd_get_flavour (p->u.indirect.section->owner) | |
2301 | == bfd_target_coff_flavour)) | |
2302 | { | |
2303 | sub = p->u.indirect.section->owner; | |
2304 | #ifdef ARM_HACKS | |
2305 | if (! sub->output_has_begun && !arm_do_last(sub)) | |
2306 | #else | |
2307 | if (! sub->output_has_begun) | |
2308 | #endif | |
2309 | { | |
2310 | if (! _bfd_coff_link_input_bfd (&finfo, sub)) | |
2311 | goto error_return; | |
2312 | sub->output_has_begun = true; | |
2313 | } | |
2314 | } | |
2315 | else if (p->type == bfd_section_reloc_link_order | |
2316 | || p->type == bfd_symbol_reloc_link_order) | |
2317 | { | |
2318 | if (! _bfd_coff_reloc_link_order (abfd, &finfo, o, p)) | |
2319 | goto error_return; | |
2320 | } | |
2321 | else | |
2322 | { | |
2323 | if (! _bfd_default_link_order (abfd, info, o, p)) | |
2324 | goto error_return; | |
2325 | } | |
2326 | } | |
2327 | } | |
2328 | ||
2329 | #ifdef ARM_HACKS | |
2330 | { | |
2331 | extern bfd* arm_get_last(); | |
2332 | bfd* last_one = arm_get_last(); | |
2333 | if (last_one) | |
2334 | { | |
2335 | if (! _bfd_coff_link_input_bfd (&finfo, last_one)) | |
2336 | goto error_return; | |
2337 | } | |
2338 | last_one->output_has_begun = true; | |
2339 | } | |
2340 | #endif | |
2341 | ||
2342 | /* Free up the buffers used by _bfd_coff_link_input_bfd. */ | |
2343 | ||
2344 | coff_debug_merge_hash_table_free (&finfo.debug_merge); | |
2345 | debug_merge_allocated = false; | |
2346 | ||
2347 | if (finfo.internal_syms != NULL) | |
2348 | { | |
2349 | free (finfo.internal_syms); | |
2350 | finfo.internal_syms = NULL; | |
2351 | } | |
2352 | if (finfo.sec_ptrs != NULL) | |
2353 | { | |
2354 | free (finfo.sec_ptrs); | |
2355 | finfo.sec_ptrs = NULL; | |
2356 | } | |
2357 | if (finfo.sym_indices != NULL) | |
2358 | { | |
2359 | free (finfo.sym_indices); | |
2360 | finfo.sym_indices = NULL; | |
2361 | } | |
2362 | if (finfo.linenos != NULL) | |
2363 | { | |
2364 | free (finfo.linenos); | |
2365 | finfo.linenos = NULL; | |
2366 | } | |
2367 | if (finfo.contents != NULL) | |
2368 | { | |
2369 | free (finfo.contents); | |
2370 | finfo.contents = NULL; | |
2371 | } | |
2372 | if (finfo.external_relocs != NULL) | |
2373 | { | |
2374 | free (finfo.external_relocs); | |
2375 | finfo.external_relocs = NULL; | |
2376 | } | |
2377 | if (finfo.internal_relocs != NULL) | |
2378 | { | |
2379 | free (finfo.internal_relocs); | |
2380 | finfo.internal_relocs = NULL; | |
2381 | } | |
2382 | ||
2383 | /* The value of the last C_FILE symbol is supposed to be the symbol | |
2384 | index of the first external symbol. Write it out again if | |
2385 | necessary. */ | |
2386 | if (finfo.last_file_index != -1 | |
2387 | && (unsigned int) finfo.last_file.n_value != obj_raw_syment_count (abfd)) | |
2388 | { | |
2389 | finfo.last_file.n_value = obj_raw_syment_count (abfd); | |
2390 | bfd_coff_swap_sym_out (abfd, (PTR) &finfo.last_file, | |
2391 | (PTR) finfo.outsyms); | |
2392 | if (bfd_seek (abfd, | |
2393 | (obj_sym_filepos (abfd) | |
2394 | + finfo.last_file_index * symesz), | |
2395 | SEEK_SET) != 0 | |
2396 | || bfd_write (finfo.outsyms, symesz, 1, abfd) != symesz) | |
2397 | return false; | |
2398 | } | |
2399 | ||
2400 | /* Write out the global symbols. */ | |
2401 | finfo.failed = false; | |
2402 | coff_link_hash_traverse (coff_hash_table (info), _bfd_coff_write_global_sym, | |
2403 | (PTR) &finfo); | |
2404 | if (finfo.failed) | |
2405 | goto error_return; | |
2406 | ||
2407 | /* The outsyms buffer is used by _bfd_coff_write_global_sym. */ | |
2408 | if (finfo.outsyms != NULL) | |
2409 | { | |
2410 | free (finfo.outsyms); | |
2411 | finfo.outsyms = NULL; | |
2412 | } | |
2413 | ||
2414 | if (info->relocateable) | |
2415 | { | |
2416 | /* Now that we have written out all the global symbols, we know | |
2417 | the symbol indices to use for relocs against them, and we can | |
2418 | finally write out the relocs. */ | |
2419 | external_relocs = ((bfd_byte *) | |
2420 | bfd_malloc (max_output_reloc_count * relsz)); | |
2421 | if (external_relocs == NULL) | |
2422 | goto error_return; | |
2423 | ||
2424 | for (o = abfd->sections; o != NULL; o = o->next) | |
2425 | { | |
2426 | struct internal_reloc *irel; | |
2427 | struct internal_reloc *irelend; | |
2428 | struct coff_link_hash_entry **rel_hash; | |
2429 | bfd_byte *erel; | |
2430 | ||
2431 | if (o->reloc_count == 0) | |
2432 | continue; | |
2433 | ||
2434 | irel = finfo.section_info[o->target_index].relocs; | |
2435 | irelend = irel + o->reloc_count; | |
2436 | rel_hash = finfo.section_info[o->target_index].rel_hashes; | |
2437 | erel = external_relocs; | |
2438 | for (; irel < irelend; irel++, rel_hash++, erel += relsz) | |
2439 | { | |
2440 | if (*rel_hash != NULL) | |
2441 | { | |
2442 | BFD_ASSERT ((*rel_hash)->indx >= 0); | |
2443 | irel->r_symndx = (*rel_hash)->indx; | |
2444 | } | |
2445 | bfd_coff_swap_reloc_out (abfd, (PTR) irel, (PTR) erel); | |
2446 | } | |
2447 | ||
2448 | if (bfd_seek (abfd, o->rel_filepos, SEEK_SET) != 0 | |
2449 | || bfd_write ((PTR) external_relocs, relsz, o->reloc_count, | |
2450 | abfd) != relsz * o->reloc_count) | |
2451 | goto error_return; | |
2452 | } | |
2453 | ||
2454 | free (external_relocs); | |
2455 | external_relocs = NULL; | |
2456 | } | |
2457 | ||
2458 | /* Free up the section information. */ | |
2459 | if (finfo.section_info != NULL) | |
2460 | { | |
2461 | unsigned int i; | |
2462 | ||
2463 | for (i = 0; i < abfd->section_count; i++) | |
2464 | { | |
2465 | if (finfo.section_info[i].relocs != NULL) | |
2466 | free (finfo.section_info[i].relocs); | |
2467 | if (finfo.section_info[i].rel_hashes != NULL) | |
2468 | free (finfo.section_info[i].rel_hashes); | |
2469 | } | |
2470 | free (finfo.section_info); | |
2471 | finfo.section_info = NULL; | |
2472 | } | |
2473 | ||
2474 | /* If we have optimized stabs strings, output them. */ | |
2475 | if (coff_hash_table (info)->stab_info != NULL) | |
2476 | { | |
2477 | if (! _bfd_write_stab_strings (abfd, &coff_hash_table (info)->stab_info)) | |
2478 | return false; | |
2479 | } | |
2480 | ||
2481 | /* Write out the string table. */ | |
2482 | if (obj_raw_syment_count (abfd) != 0) | |
2483 | { | |
2484 | if (bfd_seek (abfd, | |
2485 | (obj_sym_filepos (abfd) | |
2486 | + obj_raw_syment_count (abfd) * symesz), | |
2487 | SEEK_SET) != 0) | |
2488 | return false; | |
2489 | ||
2490 | #if STRING_SIZE_SIZE == 4 | |
2491 | bfd_h_put_32 (abfd, | |
2492 | _bfd_stringtab_size (finfo.strtab) + STRING_SIZE_SIZE, | |
2493 | (bfd_byte *) strbuf); | |
2494 | #else | |
2495 | #error Change bfd_h_put_32 | |
2496 | #endif | |
2497 | ||
2498 | if (bfd_write (strbuf, 1, STRING_SIZE_SIZE, abfd) != STRING_SIZE_SIZE) | |
2499 | return false; | |
2500 | ||
2501 | if (! _bfd_stringtab_emit (abfd, finfo.strtab)) | |
2502 | return false; | |
2503 | } | |
2504 | ||
2505 | _bfd_stringtab_free (finfo.strtab); | |
2506 | ||
2507 | /* Setting bfd_get_symcount to 0 will cause write_object_contents to | |
2508 | not try to write out the symbols. */ | |
2509 | bfd_get_symcount (abfd) = 0; | |
2510 | ||
2511 | return true; | |
2512 | ||
2513 | error_return: | |
2514 | if (debug_merge_allocated) | |
2515 | coff_debug_merge_hash_table_free (&finfo.debug_merge); | |
2516 | if (finfo.strtab != NULL) | |
2517 | _bfd_stringtab_free (finfo.strtab); | |
2518 | if (finfo.section_info != NULL) | |
2519 | { | |
2520 | unsigned int i; | |
2521 | ||
2522 | for (i = 0; i < abfd->section_count; i++) | |
2523 | { | |
2524 | if (finfo.section_info[i].relocs != NULL) | |
2525 | free (finfo.section_info[i].relocs); | |
2526 | if (finfo.section_info[i].rel_hashes != NULL) | |
2527 | free (finfo.section_info[i].rel_hashes); | |
2528 | } | |
2529 | free (finfo.section_info); | |
2530 | } | |
2531 | if (finfo.internal_syms != NULL) | |
2532 | free (finfo.internal_syms); | |
2533 | if (finfo.sec_ptrs != NULL) | |
2534 | free (finfo.sec_ptrs); | |
2535 | if (finfo.sym_indices != NULL) | |
2536 | free (finfo.sym_indices); | |
2537 | if (finfo.outsyms != NULL) | |
2538 | free (finfo.outsyms); | |
2539 | if (finfo.linenos != NULL) | |
2540 | free (finfo.linenos); | |
2541 | if (finfo.contents != NULL) | |
2542 | free (finfo.contents); | |
2543 | if (finfo.external_relocs != NULL) | |
2544 | free (finfo.external_relocs); | |
2545 | if (finfo.internal_relocs != NULL) | |
2546 | free (finfo.internal_relocs); | |
2547 | if (external_relocs != NULL) | |
2548 | free (external_relocs); | |
2549 | return false; | |
2550 | } | |
2551 | ||
2552 | static void | |
2553 | arm_bfd_coff_swap_sym_in (abfd, ext1, in1) | |
2554 | bfd *abfd; | |
2555 | PTR ext1; | |
2556 | PTR in1; | |
2557 | { | |
2558 | SYMENT *ext = (SYMENT *)ext1; | |
2559 | struct internal_syment *in = (struct internal_syment *)in1; | |
2560 | flagword flags; | |
2561 | register asection *s; | |
2562 | ||
2563 | if( ext->e.e_name[0] == 0) { | |
2564 | in->_n._n_n._n_zeroes = 0; | |
2565 | in->_n._n_n._n_offset = bfd_h_get_32(abfd, (bfd_byte *) ext->e.e.e_offset); | |
2566 | } | |
2567 | else { | |
2568 | #if SYMNMLEN != E_SYMNMLEN | |
2569 | -> Error, we need to cope with truncating or extending SYMNMLEN!; | |
2570 | #else | |
2571 | memcpy(in->_n._n_name, ext->e.e_name, SYMNMLEN); | |
2572 | #endif | |
2573 | } | |
2574 | in->n_value = bfd_h_get_32(abfd, (bfd_byte *) ext->e_value); | |
2575 | in->n_scnum = bfd_h_get_16(abfd, (bfd_byte *) ext->e_scnum); | |
2576 | if (sizeof(ext->e_type) == 2){ | |
2577 | in->n_type = bfd_h_get_16(abfd, (bfd_byte *) ext->e_type); | |
2578 | } | |
2579 | else { | |
2580 | in->n_type = bfd_h_get_32(abfd, (bfd_byte *) ext->e_type); | |
2581 | } | |
2582 | in->n_sclass = bfd_h_get_8(abfd, ext->e_sclass); | |
2583 | in->n_numaux = bfd_h_get_8(abfd, ext->e_numaux); | |
2584 | ||
2585 | if (bfd_of_glue_owner != 0) /* we already have a toc, so go home */ | |
2586 | return; | |
2587 | ||
2588 | /* save the bfd for later allocation */ | |
2589 | bfd_of_glue_owner = abfd; | |
2590 | ||
2591 | s = bfd_get_section_by_name (bfd_of_glue_owner , | |
2592 | ARM2THUMB_GLUE_SECTION_NAME); | |
2593 | ||
2594 | if (s == NULL) | |
2595 | { | |
2596 | flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY ; | |
2597 | ||
2598 | s = bfd_make_section (bfd_of_glue_owner , ARM2THUMB_GLUE_SECTION_NAME); | |
2599 | ||
2600 | if (s == NULL | |
2601 | || !bfd_set_section_flags (bfd_of_glue_owner, s, flags) | |
2602 | || !bfd_set_section_alignment (bfd_of_glue_owner, s, 2)) | |
2603 | { | |
2604 | /* FIXME: set appropriate bfd error */ | |
2605 | abort(); | |
2606 | } | |
2607 | } | |
2608 | ||
2609 | s = bfd_get_section_by_name ( bfd_of_glue_owner , THUMB2ARM_GLUE_SECTION_NAME); | |
2610 | ||
2611 | if (s == NULL) | |
2612 | { | |
2613 | flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY ; | |
2614 | ||
2615 | s = bfd_make_section (bfd_of_glue_owner , THUMB2ARM_GLUE_SECTION_NAME); | |
2616 | ||
2617 | if (s == NULL | |
2618 | || !bfd_set_section_flags (bfd_of_glue_owner, s, flags) | |
2619 | || !bfd_set_section_alignment (bfd_of_glue_owner, s, 2)) | |
2620 | { | |
2621 | /* FIXME: set appropriate bfd error krk@cygnus.com */ | |
2622 | abort(); | |
2623 | } | |
2624 | } | |
2625 | ||
2626 | return; | |
2627 | } | |
2628 | ||
2629 | static bfd_coff_backend_data arm_bfd_coff_std_swap_table = | |
2630 | { | |
2631 | coff_swap_aux_in, arm_bfd_coff_swap_sym_in, coff_swap_lineno_in, | |
2632 | coff_swap_aux_out, coff_swap_sym_out, | |
2633 | coff_swap_lineno_out, coff_swap_reloc_out, | |
2634 | coff_swap_filehdr_out, coff_swap_aouthdr_out, | |
2635 | coff_swap_scnhdr_out, | |
2636 | FILHSZ, AOUTSZ, SCNHSZ, SYMESZ, AUXESZ, RELSZ, LINESZ, | |
2637 | #ifdef COFF_LONG_FILENAMES | |
2638 | true, | |
2639 | #else | |
2640 | false, | |
2641 | #endif | |
2642 | #ifdef COFF_LONG_SECTION_NAMES | |
2643 | true, | |
2644 | #else | |
2645 | false, | |
2646 | #endif | |
2647 | COFF_DEFAULT_SECTION_ALIGNMENT_POWER, | |
2648 | coff_swap_filehdr_in, coff_swap_aouthdr_in, coff_swap_scnhdr_in, | |
2649 | coff_swap_reloc_in, coff_bad_format_hook, coff_set_arch_mach_hook, | |
2650 | coff_mkobject_hook, styp_to_sec_flags, coff_set_alignment_hook, | |
2651 | coff_slurp_symbol_table, symname_in_debug_hook, coff_pointerize_aux_hook, | |
2652 | coff_print_aux, coff_reloc16_extra_cases, coff_reloc16_estimate, | |
2653 | coff_sym_is_global, coff_compute_section_file_positions, | |
2654 | coff_start_final_link, coff_relocate_section, coff_rtype_to_howto, | |
2655 | coff_adjust_symndx, coff_link_add_one_symbol | |
2656 | }; | |
2657 | ||
177b1932 | 2658 | const bfd_target |
3ea928f5 | 2659 | #ifdef TARGET_LITTLE_SYM |
177b1932 DE |
2660 | TARGET_LITTLE_SYM = |
2661 | #else | |
2662 | armcoff_little_vec = | |
2663 | #endif | |
943fbd5b | 2664 | { |
177b1932 DE |
2665 | #ifdef TARGET_LITTLE_NAME |
2666 | TARGET_LITTLE_NAME, | |
2667 | #else | |
2668 | "coff-arm-little", | |
2669 | #endif | |
943fbd5b | 2670 | bfd_target_coff_flavour, |
46686c78 NC |
2671 | BFD_ENDIAN_LITTLE, /* data byte order is little */ |
2672 | BFD_ENDIAN_LITTLE, /* header byte order is little */ | |
943fbd5b KR |
2673 | |
2674 | (HAS_RELOC | EXEC_P | /* object flags */ | |
2675 | HAS_LINENO | HAS_DEBUG | | |
2676 | HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED), | |
2677 | ||
46686c78 | 2678 | #ifndef COFF_WITH_PE |
943fbd5b | 2679 | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */ |
46686c78 NC |
2680 | #else |
2681 | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC /* section flags */ | |
2682 | | SEC_LINK_ONCE | SEC_LINK_DUPLICATES), | |
2683 | #endif | |
2684 | ||
943fbd5b KR |
2685 | #ifdef TARGET_UNDERSCORE |
2686 | TARGET_UNDERSCORE, /* leading underscore */ | |
2687 | #else | |
2688 | 0, /* leading underscore */ | |
2689 | #endif | |
2690 | '/', /* ar_pad_char */ | |
2691 | 15, /* ar_max_namelen */ | |
2692 | ||
943fbd5b KR |
2693 | bfd_getl64, bfd_getl_signed_64, bfd_putl64, |
2694 | bfd_getl32, bfd_getl_signed_32, bfd_putl32, | |
2695 | bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */ | |
2696 | bfd_getl64, bfd_getl_signed_64, bfd_putl64, | |
2697 | bfd_getl32, bfd_getl_signed_32, bfd_putl32, | |
2698 | bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */ | |
2699 | ||
2700 | /* Note that we allow an object file to be treated as a core file as well. */ | |
da7afe3b SC |
2701 | {_bfd_dummy_target, coff_object_p, /* bfd_check_format */ |
2702 | bfd_generic_archive_p, coff_object_p}, | |
943fbd5b KR |
2703 | {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */ |
2704 | bfd_false}, | |
2705 | {bfd_false, coff_write_object_contents, /* bfd_write_contents */ | |
2706 | _bfd_write_archive_contents, bfd_false}, | |
2707 | ||
2708 | BFD_JUMP_TABLE_GENERIC (coff), | |
2709 | BFD_JUMP_TABLE_COPY (coff), | |
2710 | BFD_JUMP_TABLE_CORE (_bfd_nocore), | |
2711 | BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff), | |
2712 | BFD_JUMP_TABLE_SYMBOLS (coff), | |
2713 | BFD_JUMP_TABLE_RELOCS (coff), | |
2714 | BFD_JUMP_TABLE_WRITE (coff), | |
2715 | BFD_JUMP_TABLE_LINK (coff), | |
2716 | BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), | |
2717 | ||
e1aeb285 | 2718 | & arm_bfd_coff_std_swap_table, |
943fbd5b | 2719 | }; |
3ea928f5 | 2720 | |
177b1932 | 2721 | const bfd_target |
3ea928f5 | 2722 | #ifdef TARGET_BIG_SYM |
177b1932 DE |
2723 | TARGET_BIG_SYM = |
2724 | #else | |
2725 | armcoff_big_vec = | |
2726 | #endif | |
3ea928f5 | 2727 | { |
177b1932 DE |
2728 | #ifdef TARGET_BIG_NAME |
2729 | TARGET_BIG_NAME, | |
2730 | #else | |
2731 | "coff-arm-big", | |
2732 | #endif | |
3ea928f5 | 2733 | bfd_target_coff_flavour, |
46686c78 NC |
2734 | BFD_ENDIAN_BIG, /* data byte order is big */ |
2735 | BFD_ENDIAN_BIG, /* header byte order is big */ | |
3ea928f5 SC |
2736 | |
2737 | (HAS_RELOC | EXEC_P | /* object flags */ | |
2738 | HAS_LINENO | HAS_DEBUG | | |
2739 | HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED), | |
2740 | ||
46686c78 | 2741 | #ifndef COFF_WITH_PE |
3ea928f5 | 2742 | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */ |
46686c78 NC |
2743 | #else |
2744 | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC /* section flags */ | |
2745 | | SEC_LINK_ONCE | SEC_LINK_DUPLICATES), | |
2746 | #endif | |
2747 | ||
3ea928f5 SC |
2748 | #ifdef TARGET_UNDERSCORE |
2749 | TARGET_UNDERSCORE, /* leading underscore */ | |
2750 | #else | |
2751 | 0, /* leading underscore */ | |
2752 | #endif | |
2753 | '/', /* ar_pad_char */ | |
2754 | 15, /* ar_max_namelen */ | |
2755 | ||
3ea928f5 SC |
2756 | bfd_getb64, bfd_getb_signed_64, bfd_putb64, |
2757 | bfd_getb32, bfd_getb_signed_32, bfd_putb32, | |
2758 | bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */ | |
2759 | bfd_getb64, bfd_getb_signed_64, bfd_putb64, | |
2760 | bfd_getb32, bfd_getb_signed_32, bfd_putb32, | |
2761 | bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */ | |
2762 | ||
2763 | /* Note that we allow an object file to be treated as a core file as well. */ | |
da7afe3b SC |
2764 | {_bfd_dummy_target, coff_object_p, /* bfd_check_format */ |
2765 | bfd_generic_archive_p, coff_object_p}, | |
3ea928f5 SC |
2766 | {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */ |
2767 | bfd_false}, | |
2768 | {bfd_false, coff_write_object_contents, /* bfd_write_contents */ | |
2769 | _bfd_write_archive_contents, bfd_false}, | |
2770 | ||
2771 | BFD_JUMP_TABLE_GENERIC (coff), | |
2772 | BFD_JUMP_TABLE_COPY (coff), | |
2773 | BFD_JUMP_TABLE_CORE (_bfd_nocore), | |
2774 | BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff), | |
2775 | BFD_JUMP_TABLE_SYMBOLS (coff), | |
2776 | BFD_JUMP_TABLE_RELOCS (coff), | |
2777 | BFD_JUMP_TABLE_WRITE (coff), | |
2778 | BFD_JUMP_TABLE_LINK (coff), | |
2779 | BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic), | |
2780 | ||
e1aeb285 | 2781 | & arm_bfd_coff_std_swap_table, |
3ea928f5 | 2782 | }; |