OLD | NEW |
1 /* BFD back-end for Renesas Super-H COFF binaries. | 1 /* BFD back-end for Renesas Super-H COFF binaries. |
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, | 2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, |
3 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2011 | 3 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 |
4 Free Software Foundation, Inc. | 4 Free Software Foundation, Inc. |
5 Contributed by Cygnus Support. | 5 Contributed by Cygnus Support. |
6 Written by Steve Chamberlain, <sac@cygnus.com>. | 6 Written by Steve Chamberlain, <sac@cygnus.com>. |
7 Relaxing code written by Ian Lance Taylor, <ian@cygnus.com>. | 7 Relaxing code written by Ian Lance Taylor, <ian@cygnus.com>. |
8 | 8 |
9 This file is part of BFD, the Binary File Descriptor library. | 9 This file is part of BFD, the Binary File Descriptor library. |
10 | 10 |
11 This program is free software; you can redistribute it and/or modify | 11 This program is free software; you can redistribute it and/or modify |
12 it under the terms of the GNU General Public License as published by | 12 it under the terms of the GNU General Public License as published by |
13 the Free Software Foundation; either version 3 of the License, or | 13 the Free Software Foundation; either version 3 of the License, or |
(...skipping 17 matching lines...) Expand all Loading... |
31 #include "coff/sh.h" | 31 #include "coff/sh.h" |
32 #include "coff/internal.h" | 32 #include "coff/internal.h" |
33 | 33 |
34 #undef bfd_pe_print_pdata | 34 #undef bfd_pe_print_pdata |
35 | 35 |
36 #ifdef COFF_WITH_PE | 36 #ifdef COFF_WITH_PE |
37 #include "coff/pe.h" | 37 #include "coff/pe.h" |
38 | 38 |
39 #ifndef COFF_IMAGE_WITH_PE | 39 #ifndef COFF_IMAGE_WITH_PE |
40 static bfd_boolean sh_align_load_span | 40 static bfd_boolean sh_align_load_span |
41 PARAMS ((bfd *, asection *, bfd_byte *, | 41 (bfd *, asection *, bfd_byte *, |
42 » bfd_boolean (*) (bfd *, asection *, PTR, bfd_byte *, bfd_vma), | 42 bfd_boolean (*) (bfd *, asection *, void *, bfd_byte *, bfd_vma), |
43 » PTR, bfd_vma **, bfd_vma *, bfd_vma, bfd_vma, bfd_boolean *)); | 43 void *, bfd_vma **, bfd_vma *, bfd_vma, bfd_vma, bfd_boolean *); |
44 | 44 |
45 #define _bfd_sh_align_load_span sh_align_load_span | 45 #define _bfd_sh_align_load_span sh_align_load_span |
46 #endif | 46 #endif |
47 | 47 |
48 #define bfd_pe_print_pdata _bfd_pe_print_ce_compressed_pdata | 48 #define bfd_pe_print_pdata _bfd_pe_print_ce_compressed_pdata |
49 | 49 |
50 #else | 50 #else |
51 | 51 |
52 #define bfd_pe_print_pdata NULL | 52 #define bfd_pe_print_pdata NULL |
53 | 53 |
54 #endif /* COFF_WITH_PE. */ | 54 #endif /* COFF_WITH_PE. */ |
55 | 55 |
56 #include "libcoff.h" | 56 #include "libcoff.h" |
57 | 57 |
58 /* Internal functions. */ | 58 /* Internal functions. */ |
59 static bfd_reloc_status_type sh_reloc | |
60 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); | |
61 static long get_symbol_value PARAMS ((asymbol *)); | |
62 static bfd_boolean sh_relax_section | |
63 PARAMS ((bfd *, asection *, struct bfd_link_info *, bfd_boolean *)); | |
64 static bfd_boolean sh_relax_delete_bytes | |
65 PARAMS ((bfd *, asection *, bfd_vma, int)); | |
66 #ifndef COFF_IMAGE_WITH_PE | |
67 static const struct sh_opcode *sh_insn_info PARAMS ((unsigned int)); | |
68 #endif | |
69 static bfd_boolean sh_align_loads | |
70 PARAMS ((bfd *, asection *, struct internal_reloc *, bfd_byte *, | |
71 bfd_boolean *)); | |
72 static bfd_boolean sh_swap_insns | |
73 PARAMS ((bfd *, asection *, PTR, bfd_byte *, bfd_vma)); | |
74 static bfd_boolean sh_relocate_section | |
75 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, | |
76 struct internal_reloc *, struct internal_syment *, asection **)); | |
77 static bfd_byte *sh_coff_get_relocated_section_contents | |
78 PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *, | |
79 bfd_byte *, bfd_boolean, asymbol **)); | |
80 static reloc_howto_type * sh_coff_reloc_type_lookup PARAMS ((bfd *, bfd_reloc_co
de_real_type)); | |
81 | 59 |
82 #ifdef COFF_WITH_PE | 60 #ifdef COFF_WITH_PE |
83 /* Can't build import tables with 2**4 alignment. */ | 61 /* Can't build import tables with 2**4 alignment. */ |
84 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER 2 | 62 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER 2 |
85 #else | 63 #else |
86 /* Default section alignment to 2**4. */ | 64 /* Default section alignment to 2**4. */ |
87 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER 4 | 65 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER 4 |
88 #endif | 66 #endif |
89 | 67 |
90 #ifdef COFF_IMAGE_WITH_PE | 68 #ifdef COFF_IMAGE_WITH_PE |
91 /* Align PE executables. */ | 69 /* Align PE executables. */ |
92 #define COFF_PAGE_SIZE 0x1000 | 70 #define COFF_PAGE_SIZE 0x1000 |
93 #endif | 71 #endif |
94 | 72 |
95 /* Generate long file names. */ | 73 /* Generate long file names. */ |
96 #define COFF_LONG_FILENAMES | 74 #define COFF_LONG_FILENAMES |
97 | 75 |
98 #ifdef COFF_WITH_PE | 76 #ifdef COFF_WITH_PE |
99 static bfd_boolean in_reloc_p PARAMS ((bfd *, reloc_howto_type *)); | |
100 /* Return TRUE if this relocation should | 77 /* Return TRUE if this relocation should |
101 appear in the output .reloc section. */ | 78 appear in the output .reloc section. */ |
102 static bfd_boolean in_reloc_p (abfd, howto) | 79 |
103 bfd * abfd ATTRIBUTE_UNUSED; | 80 static bfd_boolean |
104 reloc_howto_type * howto; | 81 in_reloc_p (bfd * abfd ATTRIBUTE_UNUSED, |
| 82 » reloc_howto_type * howto) |
105 { | 83 { |
106 return ! howto->pc_relative && howto->type != R_SH_IMAGEBASE; | 84 return ! howto->pc_relative && howto->type != R_SH_IMAGEBASE; |
107 } | 85 } |
108 #endif | 86 #endif |
109 | 87 |
| 88 static bfd_reloc_status_type |
| 89 sh_reloc (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **); |
| 90 static bfd_boolean |
| 91 sh_relocate_section (bfd *, struct bfd_link_info *, bfd *, asection *, |
| 92 bfd_byte *, struct internal_reloc *, |
| 93 struct internal_syment *, asection **); |
| 94 static bfd_boolean |
| 95 sh_align_loads (bfd *, asection *, struct internal_reloc *, |
| 96 bfd_byte *, bfd_boolean *); |
| 97 |
110 /* The supported relocations. There are a lot of relocations defined | 98 /* The supported relocations. There are a lot of relocations defined |
111 in coff/internal.h which we do not expect to ever see. */ | 99 in coff/internal.h which we do not expect to ever see. */ |
112 static reloc_howto_type sh_coff_howtos[] = | 100 static reloc_howto_type sh_coff_howtos[] = |
113 { | 101 { |
114 EMPTY_HOWTO (0), | 102 EMPTY_HOWTO (0), |
115 EMPTY_HOWTO (1), | 103 EMPTY_HOWTO (1), |
116 #ifdef COFF_WITH_PE | 104 #ifdef COFF_WITH_PE |
117 /* Windows CE */ | 105 /* Windows CE */ |
118 HOWTO (R_SH_IMM32CE, /* type */ | 106 HOWTO (R_SH_IMM32CE, /* type */ |
119 0, /* rightshift */ | 107 0, /* rightshift */ |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 { \ | 388 { \ |
401 dst->r_stuff[0] = 'S'; \ | 389 dst->r_stuff[0] = 'S'; \ |
402 dst->r_stuff[1] = 'C'; \ | 390 dst->r_stuff[1] = 'C'; \ |
403 } \ | 391 } \ |
404 while (0) | 392 while (0) |
405 #endif | 393 #endif |
406 | 394 |
407 /* Get the value of a symbol, when performing a relocation. */ | 395 /* Get the value of a symbol, when performing a relocation. */ |
408 | 396 |
409 static long | 397 static long |
410 get_symbol_value (symbol) | 398 get_symbol_value (asymbol *symbol) |
411 asymbol *symbol; | |
412 { | 399 { |
413 bfd_vma relocation; | 400 bfd_vma relocation; |
414 | 401 |
415 if (bfd_is_com_section (symbol->section)) | 402 if (bfd_is_com_section (symbol->section)) |
416 relocation = 0; | 403 relocation = 0; |
417 else | 404 else |
418 relocation = (symbol->value + | 405 relocation = (symbol->value + |
419 symbol->section->output_section->vma + | 406 symbol->section->output_section->vma + |
420 symbol->section->output_offset); | 407 symbol->section->output_offset); |
421 | 408 |
422 return relocation; | 409 return relocation; |
423 } | 410 } |
424 | 411 |
425 #ifdef COFF_WITH_PE | 412 #ifdef COFF_WITH_PE |
426 /* Convert an rtype to howto for the COFF backend linker. | 413 /* Convert an rtype to howto for the COFF backend linker. |
427 Copied from coff-i386. */ | 414 Copied from coff-i386. */ |
428 #define coff_rtype_to_howto coff_sh_rtype_to_howto | 415 #define coff_rtype_to_howto coff_sh_rtype_to_howto |
429 static reloc_howto_type * coff_sh_rtype_to_howto PARAMS ((bfd *, asection *, str
uct internal_reloc *, struct coff_link_hash_entry *, struct internal_syment *, b
fd_vma *)); | 416 |
430 | 417 |
431 static reloc_howto_type * | 418 static reloc_howto_type * |
432 coff_sh_rtype_to_howto (abfd, sec, rel, h, sym, addendp) | 419 coff_sh_rtype_to_howto (bfd * abfd ATTRIBUTE_UNUSED, |
433 bfd * abfd ATTRIBUTE_UNUSED; | 420 » » » asection * sec, |
434 asection * sec; | 421 » » » struct internal_reloc * rel, |
435 struct internal_reloc * rel; | 422 » » » struct coff_link_hash_entry * h, |
436 struct coff_link_hash_entry * h; | 423 » » » struct internal_syment * sym, |
437 struct internal_syment * sym; | 424 » » » bfd_vma * addendp) |
438 bfd_vma * addendp; | |
439 { | 425 { |
440 reloc_howto_type * howto; | 426 reloc_howto_type * howto; |
441 | 427 |
442 howto = sh_coff_howtos + rel->r_type; | 428 howto = sh_coff_howtos + rel->r_type; |
443 | 429 |
444 *addendp = 0; | 430 *addendp = 0; |
445 | 431 |
446 if (howto->pc_relative) | 432 if (howto->pc_relative) |
447 *addendp += sec->vma; | 433 *addendp += sec->vma; |
448 | 434 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 { BFD_RELOC_CTOR, R_SH_IMM32 }, | 487 { BFD_RELOC_CTOR, R_SH_IMM32 }, |
502 }; | 488 }; |
503 #endif | 489 #endif |
504 | 490 |
505 /* Given a BFD reloc code, return the howto structure for the | 491 /* Given a BFD reloc code, return the howto structure for the |
506 corresponding SH PE reloc. */ | 492 corresponding SH PE reloc. */ |
507 #define coff_bfd_reloc_type_lookup sh_coff_reloc_type_lookup | 493 #define coff_bfd_reloc_type_lookup sh_coff_reloc_type_lookup |
508 #define coff_bfd_reloc_name_lookup sh_coff_reloc_name_lookup | 494 #define coff_bfd_reloc_name_lookup sh_coff_reloc_name_lookup |
509 | 495 |
510 static reloc_howto_type * | 496 static reloc_howto_type * |
511 sh_coff_reloc_type_lookup (abfd, code) | 497 sh_coff_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED, |
512 bfd * abfd ATTRIBUTE_UNUSED; | 498 » » » bfd_reloc_code_real_type code) |
513 bfd_reloc_code_real_type code; | |
514 { | 499 { |
515 unsigned int i; | 500 unsigned int i; |
516 | 501 |
517 for (i = ARRAY_SIZE (sh_reloc_map); i--;) | 502 for (i = ARRAY_SIZE (sh_reloc_map); i--;) |
518 if (sh_reloc_map[i].bfd_reloc_val == code) | 503 if (sh_reloc_map[i].bfd_reloc_val == code) |
519 return &sh_coff_howtos[(int) sh_reloc_map[i].shcoff_reloc_val]; | 504 return &sh_coff_howtos[(int) sh_reloc_map[i].shcoff_reloc_val]; |
520 | 505 |
521 (*_bfd_error_handler) (_("SH Error: unknown reloc type %d"), code); | 506 (*_bfd_error_handler) (_("SH Error: unknown reloc type %d"), code); |
522 return NULL; | 507 return NULL; |
523 } | 508 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 || (reloc).r_type == R_SH_SWITCH32 \ | 553 || (reloc).r_type == R_SH_SWITCH32 \ |
569 || (reloc).r_type == R_SH_USES \ | 554 || (reloc).r_type == R_SH_USES \ |
570 || (reloc).r_type == R_SH_COUNT \ | 555 || (reloc).r_type == R_SH_COUNT \ |
571 || (reloc).r_type == R_SH_ALIGN) \ | 556 || (reloc).r_type == R_SH_ALIGN) \ |
572 cache_ptr->addend = (reloc).r_offset; \ | 557 cache_ptr->addend = (reloc).r_offset; \ |
573 } | 558 } |
574 | 559 |
575 /* This is the howto function for the SH relocations. */ | 560 /* This is the howto function for the SH relocations. */ |
576 | 561 |
577 static bfd_reloc_status_type | 562 static bfd_reloc_status_type |
578 sh_reloc (abfd, reloc_entry, symbol_in, data, input_section, output_bfd, | 563 sh_reloc (bfd * abfd, |
579 » error_message) | 564 » arelent * reloc_entry, |
580 bfd *abfd; | 565 » asymbol * symbol_in, |
581 arelent *reloc_entry; | 566 » void * data, |
582 asymbol *symbol_in; | 567 » asection * input_section, |
583 PTR data; | 568 » bfd * output_bfd, |
584 asection *input_section; | 569 » char ** error_message ATTRIBUTE_UNUSED) |
585 bfd *output_bfd; | |
586 char **error_message ATTRIBUTE_UNUSED; | |
587 { | 570 { |
588 unsigned long insn; | 571 unsigned long insn; |
589 bfd_vma sym_value; | 572 bfd_vma sym_value; |
590 unsigned short r_type; | 573 unsigned short r_type; |
591 bfd_vma addr = reloc_entry->address; | 574 bfd_vma addr = reloc_entry->address; |
592 bfd_byte *hit_data = addr + (bfd_byte *) data; | 575 bfd_byte *hit_data = addr + (bfd_byte *) data; |
593 | 576 |
594 r_type = reloc_entry->howto->type; | 577 r_type = reloc_entry->howto->type; |
595 | 578 |
596 if (output_bfd != NULL) | 579 if (output_bfd != NULL) |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 /* We can do relaxing. */ | 646 /* We can do relaxing. */ |
664 #define coff_bfd_relax_section sh_relax_section | 647 #define coff_bfd_relax_section sh_relax_section |
665 | 648 |
666 /* We use the special COFF backend linker. */ | 649 /* We use the special COFF backend linker. */ |
667 #define coff_relocate_section sh_relocate_section | 650 #define coff_relocate_section sh_relocate_section |
668 | 651 |
669 /* When relaxing, we need to use special code to get the relocated | 652 /* When relaxing, we need to use special code to get the relocated |
670 section contents. */ | 653 section contents. */ |
671 #define coff_bfd_get_relocated_section_contents \ | 654 #define coff_bfd_get_relocated_section_contents \ |
672 sh_coff_get_relocated_section_contents | 655 sh_coff_get_relocated_section_contents |
error: old chunk mismatch |
None
OLD | NEW |