Changeset 609 for branches/GNU/src/binutils/gas/write.c
- Timestamp:
- Aug 16, 2003, 6:59:22 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/binutils/gas/write.c
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r608 r609 1 1 /* write.c - emit .o file 2 2 Copyright 1986, 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 3 1998, 1999, 2000, 2001 3 1998, 1999, 2000, 2001, 2002, 2003 4 4 Free Software Foundation, Inc. 5 5 … … 29 29 #include "dwarf2dbg.h" 30 30 31 /* This looks like a good idea. Let's try turning it on always, for now. */32 #undef BFD_FAST_SECTION_FILL33 #define BFD_FAST_SECTION_FILL34 35 31 #ifndef TC_ADJUST_RELOC_COUNT 36 #define TC_ADJUST_RELOC_COUNT(FIX P,COUNT)32 #define TC_ADJUST_RELOC_COUNT(FIX, COUNT) 37 33 #endif 38 34 39 35 #ifndef TC_FORCE_RELOCATION 40 #define TC_FORCE_RELOCATION(FIXP) 0 41 #endif 42 43 #ifndef TC_FORCE_RELOCATION_SECTION 44 #define TC_FORCE_RELOCATION_SECTION(FIXP,SEG) TC_FORCE_RELOCATION(FIXP) 36 #define TC_FORCE_RELOCATION(FIX) \ 37 (generic_force_reloc (FIX)) 38 #endif 39 40 #ifndef TC_FORCE_RELOCATION_ABS 41 #define TC_FORCE_RELOCATION_ABS(FIX) \ 42 (TC_FORCE_RELOCATION (FIX)) 43 #endif 44 45 #ifndef TC_FORCE_RELOCATION_LOCAL 46 #define TC_FORCE_RELOCATION_LOCAL(FIX) \ 47 (!(FIX)->fx_pcrel \ 48 || (FIX)->fx_plt \ 49 || TC_FORCE_RELOCATION (FIX)) 50 #endif 51 52 #ifndef TC_FORCE_RELOCATION_SUB_SAME 53 #define TC_FORCE_RELOCATION_SUB_SAME(FIX, SEG) \ 54 (! SEG_NORMAL (SEG)) 55 #endif 56 57 #ifndef TC_FORCE_RELOCATION_SUB_ABS 58 #define TC_FORCE_RELOCATION_SUB_ABS(FIX) 0 59 #endif 60 61 #ifndef TC_FORCE_RELOCATION_SUB_LOCAL 62 #ifdef DIFF_EXPR_OK 63 #define TC_FORCE_RELOCATION_SUB_LOCAL(FIX) 0 64 #else 65 #define TC_FORCE_RELOCATION_SUB_LOCAL(FIX) 1 66 #endif 67 #endif 68 69 #ifndef TC_VALIDATE_FIX_SUB 70 #ifdef UNDEFINED_DIFFERENCE_OK 71 /* The PA needs this for PIC code generation. */ 72 #define TC_VALIDATE_FIX_SUB(FIX) 1 73 #else 74 #ifdef BFD_ASSEMBLER 75 #define TC_VALIDATE_FIX_SUB(FIX) \ 76 ((FIX)->fx_r_type == BFD_RELOC_GPREL32 \ 77 || (FIX)->fx_r_type == BFD_RELOC_GPREL16) 78 #else 79 #define TC_VALIDATE_FIX_SUB(FIX) 0 80 #endif 81 #endif 45 82 #endif 46 83 … … 49 86 #endif 50 87 51 #ifndef TC_FIX_ADJUSTABLE 52 #define TC_FIX_ADJUSTABLE(fix) 1 88 #ifndef MD_APPLY_SYM_VALUE 89 #define MD_APPLY_SYM_VALUE(FIX) 1 90 #endif 91 92 #ifndef TC_FINALIZE_SYMS_BEFORE_SIZE_SEG 93 #define TC_FINALIZE_SYMS_BEFORE_SIZE_SEG 1 53 94 #endif 54 95 55 96 #ifndef MD_PCREL_FROM_SECTION 56 #define MD_PCREL_FROM_SECTION(FIX P, SEC) md_pcrel_from(FIXP)97 #define MD_PCREL_FROM_SECTION(FIX, SEC) md_pcrel_from (FIX) 57 98 #endif 58 99 59 100 #ifndef WORKING_DOT_WORD 60 extern CONST int md_short_jump_size; 61 extern CONST int md_long_jump_size; 62 #endif 101 extern const int md_short_jump_size; 102 extern const int md_long_jump_size; 103 #endif 104 105 /* Used to control final evaluation of expressions. */ 106 int finalize_syms = 0; 63 107 64 108 int symbol_table_frozen; 109 110 symbolS *abs_section_sym; 111 112 /* Remember the value of dot when parsing expressions. */ 113 addressT dot_value; 114 65 115 void print_fixup PARAMS ((fixS *)); 66 116 … … 103 153 104 154 #ifdef BFD_ASSEMBLER 155 #define RELOC_ENUM enum bfd_reloc_code_real 156 #else 157 #define RELOC_ENUM int 158 #endif 159 105 160 static fixS *fix_new_internal PARAMS ((fragS *, int where, int size, 106 161 symbolS *add, symbolS *sub, 107 162 offsetT offset, int pcrel, 108 bfd_reloc_code_real_type r_type)); 109 #else 110 static fixS *fix_new_internal PARAMS ((fragS *, int where, int size, 111 symbolS *add, symbolS *sub, 112 offsetT offset, int pcrel, 113 int r_type)); 114 #endif 163 RELOC_ENUM r_type)); 115 164 #if defined (BFD_ASSEMBLER) || (!defined (BFD) && !defined (OBJ_VMS)) 116 static long fixup_segment PARAMS ((fixS * fixP, segT this_segment_type));165 static long fixup_segment PARAMS ((fixS *, segT)); 117 166 #endif 118 167 static relax_addressT relax_align PARAMS ((relax_addressT addr, int align)); … … 123 172 static void chain_frchains_together PARAMS ((bfd *, segT, PTR)); 124 173 static void cvt_frag_to_fill PARAMS ((segT, fragS *)); 125 static void relax_seg PARAMS ((bfd *, asection *, PTR));126 static void size_seg PARAMS ((bfd *, asection *, PTR));127 174 static void adjust_reloc_syms PARAMS ((bfd *, asection *, PTR)); 175 static void fix_segment PARAMS ((bfd *, asection *, PTR)); 128 176 static void write_relocs PARAMS ((bfd *, asection *, PTR)); 129 177 static void write_contents PARAMS ((bfd *, asection *, PTR)); … … 137 185 static void remove_subsegs PARAMS ((frchainS *, int, fragS **, fragS **)); 138 186 static void relax_and_size_all_segments PARAMS ((void)); 139 #endif140 #if defined (BFD_ASSEMBLER) && defined (OBJ_COFF) && defined (TE_GO32)141 static void set_segment_vma PARAMS ((bfd *, asection *, PTR));142 187 #endif 143 188 … … 154 199 offsetT offset; /* X_add_number. */ 155 200 int pcrel; /* TRUE if PC-relative relocation. */ 156 #ifdef BFD_ASSEMBLER 157 bfd_reloc_code_real_type r_type; /* Relocation type. */ 158 #else 159 int r_type; /* Relocation type. */ 160 #endif 201 RELOC_ENUM r_type ATTRIBUTE_UNUSED; /* Relocation type. */ 161 202 { 162 203 fixS *fixP; … … 178 219 fixP->fx_subsy = sub_symbol; 179 220 fixP->fx_offset = offset; 221 fixP->fx_dot_value = dot_value; 180 222 fixP->fx_pcrel = pcrel; 181 223 fixP->fx_plt = 0; … … 249 291 offsetT offset; /* X_add_number. */ 250 292 int pcrel; /* TRUE if PC-relative relocation. */ 251 #ifdef BFD_ASSEMBLER 252 bfd_reloc_code_real_type r_type; /* Relocation type. */ 253 #else 254 int r_type; /* Relocation type. */ 255 #endif 293 RELOC_ENUM r_type; /* Relocation type. */ 256 294 { 257 295 return fix_new_internal (frag, where, size, add_symbol, … … 270 308 expressionS *exp; /* Expression. */ 271 309 int pcrel; /* TRUE if PC-relative relocation. */ 272 #ifdef BFD_ASSEMBLER 273 bfd_reloc_code_real_type r_type; /* Relocation type. */ 274 #else 275 int r_type; /* Relocation type. */ 276 #endif 310 RELOC_ENUM r_type; /* Relocation type. */ 277 311 { 278 312 symbolS *add = NULL; … … 339 373 340 374 return fix_new_internal (frag, where, size, add, sub, off, pcrel, r_type); 375 } 376 377 /* Generic function to determine whether a fixup requires a relocation. */ 378 int 379 generic_force_reloc (fix) 380 fixS *fix; 381 { 382 #ifdef BFD_ASSEMBLER 383 if (fix->fx_r_type == BFD_RELOC_VTABLE_INHERIT 384 || fix->fx_r_type == BFD_RELOC_VTABLE_ENTRY) 385 return 1; 386 #endif 387 return S_FORCE_RELOC (fix->fx_addsy, fix->fx_subsy == NULL); 341 388 } 342 389 … … 523 570 _("attempt to .org/.space backwards? (%ld)"), 524 571 (long) fragP->fr_offset); 572 fragP->fr_offset = 0; 525 573 } 526 574 fragP->fr_type = rs_fill; … … 599 647 600 648 #ifdef BFD_ASSEMBLER 649 static void relax_seg PARAMS ((bfd *, asection *, PTR)); 601 650 static void 602 relax_seg (abfd, sec, do_code)603 bfd *abfd ;651 relax_seg (abfd, sec, xxx) 652 bfd *abfd ATTRIBUTE_UNUSED; 604 653 asection *sec; 605 PTR do_code; 606 { 607 flagword flags = bfd_get_section_flags (abfd, sec); 654 PTR xxx; 655 { 608 656 segment_info_type *seginfo = seg_info (sec); 609 657 610 if (!(flags & SEC_CODE) == !do_code 611 && seginfo && seginfo->frchainP) 612 relax_segment (seginfo->frchainP->frch_root, sec); 613 } 614 658 if (seginfo && seginfo->frchainP 659 && relax_segment (seginfo->frchainP->frch_root, sec)) 660 { 661 int *result = (int *) xxx; 662 *result = 1; 663 } 664 } 665 666 static void size_seg PARAMS ((bfd *, asection *, PTR)); 615 667 static void 616 668 size_seg (abfd, sec, xxx) … … 653 705 flags &= ~SEC_RELOC; 654 706 x = bfd_set_section_flags (abfd, sec, flags); 655 assert (x == true);707 assert (x); 656 708 657 709 newsize = md_section_align (sec, size); 658 710 x = bfd_set_section_size (abfd, sec, newsize); 659 assert (x == true);711 assert (x); 660 712 661 713 /* If the size had to be rounded up, add some padding in the last … … 669 721 fragp = fragp->fr_next; 670 722 last->fr_address = size; 671 fragp->fr_offset += newsize - size; 723 if ((newsize - size) % fragp->fr_var == 0) 724 fragp->fr_offset += (newsize - size) / fragp->fr_var; 725 else 726 /* If we hit this abort, it's likely due to subsegs_finish not 727 providing sufficient alignment on the last frag, and the 728 machine dependent code using alignment frags with fr_var 729 greater than 1. */ 730 abort (); 672 731 } 673 732 … … 719 778 #endif 720 779 780 /* This pass over fixups decides whether symbols can be replaced with 781 section symbols. */ 782 721 783 static void 722 784 adjust_reloc_syms (abfd, sec, xxx) … … 753 815 symbols, though, since they are not in the regular symbol 754 816 table. */ 755 if (sym != NULL) 756 resolve_symbol_value (sym, 1); 817 resolve_symbol_value (sym); 757 818 758 819 if (fixp->fx_subsy != NULL) 759 resolve_symbol_value (fixp->fx_subsy , 1);820 resolve_symbol_value (fixp->fx_subsy); 760 821 761 822 /* If this symbol is equated to an undefined symbol, convert 762 823 the fixup to being against that symbol. */ 763 if (sym != NULL && symbol_equated_p (sym) 764 && (! S_IS_DEFINED (sym) || S_IS_COMMON (sym))) 824 if (symbol_equated_reloc_p (sym)) 765 825 { 766 826 fixp->fx_offset += symbol_get_value_expression (sym)->X_add_number; … … 769 829 } 770 830 771 if (sym != NULL && symbol_mri_common_p (sym))831 if (symbol_mri_common_p (sym)) 772 832 { 773 833 /* These symbols are handled specially in fixup_segment. */ 774 goto done;834 continue; 775 835 } 776 836 837 /* If the symbol is undefined, common, weak, or global (ELF 838 shared libs), we can't replace it with the section symbol. */ 839 if (S_FORCE_RELOC (fixp->fx_addsy, 1)) 840 continue; 841 842 /* Is there some other (target cpu dependent) reason we can't adjust 843 this one? (E.g. relocations involving function addresses on 844 the PA. */ 845 #ifdef tc_fix_adjustable 846 if (! tc_fix_adjustable (fixp)) 847 continue; 848 #endif 849 850 /* Since we're reducing to section symbols, don't attempt to reduce 851 anything that's already using one. */ 852 if (symbol_section_p (sym)) 853 continue; 854 777 855 symsec = S_GET_SEGMENT (sym); 778 779 856 if (symsec == NULL) 780 857 abort (); … … 782 859 if (bfd_is_abs_section (symsec)) 783 860 { 784 /* The fixup_segment routine will not use this symbol in a 785 relocation unless TC_FORCE_RELOCATION returns 1. */ 786 if (TC_FORCE_RELOCATION (fixp)) 787 { 788 symbol_mark_used_in_reloc (fixp->fx_addsy); 789 #ifdef UNDEFINED_DIFFERENCE_OK 790 if (fixp->fx_subsy != NULL) 791 symbol_mark_used_in_reloc (fixp->fx_subsy); 792 #endif 793 } 794 goto done; 795 } 796 797 /* If it's one of these sections, assume the symbol is 798 definitely going to be output. The code in 799 md_estimate_size_before_relax in tc-mips.c uses this test 800 as well, so if you change this code you should look at that 801 code. */ 802 if (bfd_is_und_section (symsec) 803 || bfd_is_com_section (symsec)) 804 { 805 symbol_mark_used_in_reloc (fixp->fx_addsy); 806 #ifdef UNDEFINED_DIFFERENCE_OK 807 /* We have the difference of an undefined symbol and some 808 other symbol. Make sure to mark the other symbol as used 809 in a relocation so that it will always be output. */ 810 if (fixp->fx_subsy) 811 symbol_mark_used_in_reloc (fixp->fx_subsy); 812 #endif 813 goto done; 861 /* The fixup_segment routine normally will not use this 862 symbol in a relocation. */ 863 continue; 814 864 } 815 865 … … 820 870 if (symsec != sec && ! S_IS_LOCAL (sym)) 821 871 { 822 boolean linkonce; 823 824 linkonce = false; 825 #ifdef BFD_ASSEMBLER 826 if ((bfd_get_section_flags (stdoutput, symsec) & SEC_LINK_ONCE) 827 != 0) 828 linkonce = true; 829 #endif 830 #ifdef OBJ_ELF 831 /* The GNU toolchain uses an extension for ELF: a section 832 beginning with the magic string .gnu.linkonce is a 833 linkonce section. */ 834 if (strncmp (segment_name (symsec), ".gnu.linkonce", 835 sizeof ".gnu.linkonce" - 1) == 0) 836 linkonce = true; 837 #endif 838 839 if (linkonce) 840 { 841 symbol_mark_used_in_reloc (fixp->fx_addsy); 842 #ifdef UNDEFINED_DIFFERENCE_OK 843 if (fixp->fx_subsy != NULL) 844 symbol_mark_used_in_reloc (fixp->fx_subsy); 845 #endif 846 goto done; 847 } 872 if ((symsec->flags & SEC_LINK_ONCE) != 0 873 || (IS_ELF 874 /* The GNU toolchain uses an extension for ELF: a 875 section beginning with the magic string 876 .gnu.linkonce is a linkonce section. */ 877 && strncmp (segment_name (symsec), ".gnu.linkonce", 878 sizeof ".gnu.linkonce" - 1) == 0)) 879 continue; 848 880 } 849 881 850 /* Since we're reducing to section symbols, don't attempt to reduce 851 anything that's already using one. */ 852 if (symbol_section_p (sym)) 853 { 854 symbol_mark_used_in_reloc (fixp->fx_addsy); 855 goto done; 856 } 857 858 #ifdef BFD_ASSEMBLER 859 /* We can never adjust a reloc against a weak symbol. If we 860 did, and the weak symbol was overridden by a real symbol 861 somewhere else, then our relocation would be pointing at 862 the wrong area of memory. */ 863 if (S_IS_WEAK (sym)) 864 { 865 symbol_mark_used_in_reloc (fixp->fx_addsy); 866 goto done; 867 } 868 #endif 869 870 /* Is there some other reason we can't adjust this one? (E.g., 871 call/bal links in i960-bout symbols.) */ 872 #ifdef obj_fix_adjustable 873 if (! obj_fix_adjustable (fixp)) 874 { 875 symbol_mark_used_in_reloc (fixp->fx_addsy); 876 goto done; 877 } 878 #endif 879 880 /* Is there some other (target cpu dependent) reason we can't adjust 881 this one? (E.g. relocations involving function addresses on 882 the PA. */ 883 #ifdef tc_fix_adjustable 884 if (! tc_fix_adjustable (fixp)) 885 { 886 symbol_mark_used_in_reloc (fixp->fx_addsy); 887 goto done; 888 } 889 #endif 890 891 /* If the section symbol isn't going to be output, the relocs 892 at least should still work. If not, figure out what to do 893 when we run into that case. 894 895 We refetch the segment when calling section_symbol, rather 882 /* Never adjust a reloc against local symbol in a merge section 883 with non-zero addend. */ 884 if ((symsec->flags & SEC_MERGE) != 0 885 && (fixp->fx_offset != 0 || fixp->fx_subsy != NULL)) 886 continue; 887 888 /* Never adjust a reloc against TLS local symbol. */ 889 if ((symsec->flags & SEC_THREAD_LOCAL) != 0) 890 continue; 891 892 /* We refetch the segment when calling section_symbol, rather 896 893 than using symsec, because S_GET_VALUE may wind up changing 897 894 the section when it calls resolve_symbol_value. */ 898 895 fixp->fx_offset += S_GET_VALUE (sym); 899 896 fixp->fx_addsy = section_symbol (S_GET_SEGMENT (sym)); 900 symbol_mark_used_in_reloc (fixp->fx_addsy);901 897 #ifdef DEBUG5 902 898 fprintf (stderr, "\nadjusted fixup:\n"); 903 899 print_fixup (fixp); 904 900 #endif 905 906 done:907 ;908 901 } 909 #if 1 /* def RELOC_REQUIRES_SYMBOL */910 else911 {912 /* There was no symbol required by this relocation. However,913 BFD doesn't really handle relocations without symbols well.914 (At least, the COFF support doesn't.) So for now we fake up915 a local symbol in the absolute section. */916 917 fixp->fx_addsy = section_symbol (absolute_section);918 #if 0919 fixp->fx_addsy->sy_used_in_reloc = 1;920 #endif921 }922 #endif923 902 924 903 dump_section_relocs (abfd, sec, stderr); 904 } 905 906 static void 907 fix_segment (abfd, sec, xxx) 908 bfd *abfd ATTRIBUTE_UNUSED; 909 asection *sec; 910 PTR xxx ATTRIBUTE_UNUSED; 911 { 912 segment_info_type *seginfo = seg_info (sec); 913 914 fixup_segment (seginfo->fix_root, sec); 925 915 } 926 916 … … 943 933 return; 944 934 945 fixup_segment (seginfo->fix_root, sec);946 947 935 n = 0; 948 936 for (fixp = seginfo->fix_root; fixp; fixp = fixp->fx_next) … … 968 956 969 957 /* If this is an undefined symbol which was equated to another 970 symbol, then usegenerate the reloc against the latter symbol958 symbol, then generate the reloc against the latter symbol 971 959 rather than the former. */ 972 960 sym = fixp->fx_addsy; 973 while (symbol_equated_p (sym) 974 && (! S_IS_DEFINED (sym) || S_IS_COMMON (sym))) 961 while (symbol_equated_reloc_p (sym)) 975 962 { 976 963 symbolS *n; … … 1009 996 break; 1010 997 case bfd_reloc_overflow: 1011 as_bad_where (fixp->fx_file, fixp->fx_line, _("relocation overflow")); 998 as_bad_where (fixp->fx_file, fixp->fx_line, 999 _("relocation overflow")); 1012 1000 break; 1013 1001 case bfd_reloc_outofrange: 1014 as_bad_where (fixp->fx_file, fixp->fx_line, _("relocation out of range")); 1002 as_bad_where (fixp->fx_file, fixp->fx_line, 1003 _("relocation out of range")); 1015 1004 break; 1016 1005 default: … … 1029 1018 { 1030 1019 arelent **reloc; 1031 char *data;1032 1020 bfd_reloc_status_type s; 1033 1021 symbolS *sym; … … 1044 1032 rather than the former. */ 1045 1033 sym = fixp->fx_addsy; 1046 while (symbol_equated_p (sym) 1047 && (! S_IS_DEFINED (sym) || S_IS_COMMON (sym))) 1048 sym = symbol_get_value_expression (sym)->X_add_symbol; 1034 while (symbol_equated_reloc_p (sym)) 1035 { 1036 symbolS *n; 1037 1038 /* We must avoid looping, as that can occur with a badly 1039 written program. */ 1040 n = symbol_get_value_expression (sym)->X_add_symbol; 1041 if (n == sym) 1042 break; 1043 fixp->fx_offset += symbol_get_value_expression (sym)->X_add_number; 1044 sym = n; 1045 } 1049 1046 fixp->fx_addsy = sym; 1050 1047 … … 1056 1053 assert (i <= n); 1057 1054 } 1058 data = fixp->fx_frag->fr_literal + fixp->fx_where;1059 1055 if (fixp->fx_where + fixp->fx_size 1060 1056 > fixp->fx_frag->fr_fix + fixp->fx_frag->fr_offset) … … 1075 1071 _("relocation overflow")); 1076 1072 break; 1073 case bfd_reloc_outofrange: 1074 as_bad_where (fixp->fx_file, fixp->fx_line, 1075 _("relocation out of range")); 1076 break; 1077 1077 default: 1078 as_fatal (_("%s:%u: bad return from bfd_install_relocation "),1079 fixp->fx_file, fixp->fx_line );1078 as_fatal (_("%s:%u: bad return from bfd_install_relocation: %x"), 1079 fixp->fx_file, fixp->fx_line, s); 1080 1080 } 1081 1081 } … … 1160 1160 f->fr_literal, (file_ptr) offset, 1161 1161 (bfd_size_type) f->fr_fix); 1162 if ( x == false)1162 if (!x) 1163 1163 { 1164 1164 bfd_perror (stdoutput->filename); … … 1184 1184 (file_ptr) offset, 1185 1185 (bfd_size_type) fill_size); 1186 if ( x == false)1186 if (!x) 1187 1187 { 1188 1188 bfd_perror (stdoutput->filename); … … 1218 1218 (stdoutput, sec, buf, (file_ptr) offset, 1219 1219 (bfd_size_type) n_per_buf * fill_size); 1220 if ( x != true)1221 as_fatal (_(" Cannot write to output file."));1220 if (!x) 1221 as_fatal (_("cannot write to output file")); 1222 1222 offset += n_per_buf * fill_size; 1223 1223 } … … 1352 1352 asymbol **asympp; 1353 1353 symbolS *symp; 1354 b oolean result;1355 extern PTR bfd_alloc PARAMS ((bfd *, size_t));1354 bfd_boolean result; 1355 extern PTR bfd_alloc PARAMS ((bfd *, bfd_size_type)); 1356 1356 1357 1357 /* Count symbols. We can't rely on a count made by the loop in … … 1365 1365 { 1366 1366 int i; 1367 1368 asympp = (asymbol **) bfd_alloc (stdoutput, 1369 nsyms * sizeof (asymbol *));1367 bfd_size_type amt = (bfd_size_type) nsyms * sizeof (asymbol *); 1368 1369 asympp = (asymbol **) bfd_alloc (stdoutput, amt); 1370 1370 symp = symbol_rootP; 1371 1371 for (i = 0; i < nsyms; i++, symp = symbol_next (symp)) … … 1378 1378 asympp = 0; 1379 1379 result = bfd_set_symtab (stdoutput, asympp, nsyms); 1380 assert (result == true);1380 assert (result); 1381 1381 symbol_table_frozen = 1; 1382 1382 } 1383 1383 #endif 1384 1385 #if defined (BFD_ASSEMBLER) && defined (OBJ_COFF) && defined (TE_GO32)1386 static void1387 set_segment_vma (abfd, sec, xxx)1388 bfd *abfd;1389 asection *sec;1390 PTR xxx ATTRIBUTE_UNUSED;1391 {1392 static bfd_vma addr = 0;1393 1394 bfd_set_section_vma (abfd, sec, addr);1395 addr += bfd_section_size (abfd, sec);1396 }1397 #endif /* BFD_ASSEMBLER && OBJ_COFF && !TE_PE */1398 1384 1399 1385 /* Finish the subsegments. After every sub-segment, we fake an … … 1404 1390 1405 1391 #ifndef SUB_SEGMENT_ALIGN 1392 #ifdef HANDLE_ALIGN 1393 /* The last subsegment gets an aligment corresponding to the alignment 1394 of the section. This allows proper nop-filling at the end of 1395 code-bearing sections. */ 1396 #define SUB_SEGMENT_ALIGN(SEG, FRCHAIN) \ 1397 (!(FRCHAIN)->frch_next || (FRCHAIN)->frch_next->frch_seg != (SEG) \ 1398 ? get_recorded_alignment (SEG) : 0) 1399 #else 1406 1400 #ifdef BFD_ASSEMBLER 1407 #define SUB_SEGMENT_ALIGN(SEG ) (0)1401 #define SUB_SEGMENT_ALIGN(SEG, FRCHAIN) 0 1408 1402 #else 1409 #define SUB_SEGMENT_ALIGN(SEG) (2) 1403 #define SUB_SEGMENT_ALIGN(SEG, FRCHAIN) 2 1404 #endif 1410 1405 #endif 1411 1406 #endif … … 1418 1413 for (frchainP = frchain_root; frchainP; frchainP = frchainP->frch_next) 1419 1414 { 1420 int alignment ;1415 int alignment = 0; 1421 1416 1422 1417 subseg_set (frchainP->frch_seg, frchainP->frch_subseg); … … 1425 1420 any alignment is meaningless, and, moreover, will look weird 1426 1421 if we are generating a listing. */ 1427 alignment = had_errors () ? 0 : SUB_SEGMENT_ALIGN (now_seg); 1428 1429 /* The last subsegment gets an aligment corresponding to the 1430 alignment of the section. This allows proper nop-filling 1431 at the end of code-bearing sections. */ 1432 if (!frchainP->frch_next || frchainP->frch_next->frch_seg != now_seg) 1433 alignment = get_recorded_alignment (now_seg); 1422 if (!had_errors ()) 1423 { 1424 alignment = SUB_SEGMENT_ALIGN (now_seg, frchainP); 1425 #ifdef BFD_ASSEMBLER 1426 if ((bfd_get_section_flags (now_seg->owner, now_seg) & SEC_MERGE) 1427 && now_seg->entsize) 1428 { 1429 unsigned int entsize = now_seg->entsize; 1430 int entalign = 0; 1431 1432 while ((entsize & 1) == 0) 1433 { 1434 ++entalign; 1435 entsize >>= 1; 1436 } 1437 if (entalign > alignment) 1438 alignment = entalign; 1439 } 1440 #endif 1441 } 1434 1442 1435 1443 if (subseg_text_p (now_seg)) … … 1468 1476 { 1469 1477 if (n_warns || n_errs) 1470 as_warn (_("%d error%s, %d warning%s, generating bad object file .\n"),1478 as_warn (_("%d error%s, %d warning%s, generating bad object file"), 1471 1479 n_errs, n_errs == 1 ? "" : "s", 1472 1480 n_warns, n_warns == 1 ? "" : "s"); … … 1475 1483 { 1476 1484 if (n_errs) 1477 as_fatal (_("%d error%s, %d warning%s, no object file generated .\n"),1485 as_fatal (_("%d error%s, %d warning%s, no object file generated"), 1478 1486 n_errs, n_errs == 1 ? "" : "s", 1479 1487 n_warns, n_warns == 1 ? "" : "s"); … … 1494 1502 /* Remove the sections created by gas for its own purposes. */ 1495 1503 { 1496 asection **seclist , *sec;1504 asection **seclist; 1497 1505 int i; 1498 1506 1499 1507 seclist = &stdoutput->sections; 1500 while ( seclist &&*seclist)1508 while (*seclist) 1501 1509 { 1502 sec = *seclist; 1503 while (sec == reg_section || sec == expr_section) 1510 if (*seclist == reg_section || *seclist == expr_section) 1504 1511 { 1505 sec = sec->next; 1506 *seclist = sec; 1512 bfd_section_list_remove (stdoutput, seclist); 1507 1513 stdoutput->section_count--; 1508 if (!sec)1509 break;1510 1514 } 1511 if (*seclist)1515 else 1512 1516 seclist = &(*seclist)->next; 1513 1517 } … … 1534 1538 1535 1539 #ifdef BFD_ASSEMBLER 1536 bfd_map_over_sections (stdoutput, relax_seg, (char *) 1); 1537 bfd_map_over_sections (stdoutput, relax_seg, (char *) 0); 1540 while (1) 1541 { 1542 int changed; 1543 1544 #ifndef WORKING_DOT_WORD 1545 /* We need to reset the markers in the broken word list and 1546 associated frags between calls to relax_segment (via 1547 relax_seg). Since the broken word list is global, we do it 1548 once per round, rather than locally in relax_segment for each 1549 segment. */ 1550 struct broken_word *brokp; 1551 1552 for (brokp = broken_words; 1553 brokp != (struct broken_word *) NULL; 1554 brokp = brokp->next_broken_word) 1555 { 1556 brokp->added = 0; 1557 1558 if (brokp->dispfrag != (fragS *) NULL 1559 && brokp->dispfrag->fr_type == rs_broken_word) 1560 brokp->dispfrag->fr_subtype = 0; 1561 } 1562 #endif 1563 1564 changed = 0; 1565 bfd_map_over_sections (stdoutput, relax_seg, &changed); 1566 if (!changed) 1567 break; 1568 } 1569 1570 /* Note - Most ports will use the default value of 1571 TC_FINALIZE_SYMS_BEFORE_SIZE_SEG, which 1. This will force 1572 local symbols to be resolved, removing their frag information. 1573 Some ports however, will not have finished relaxing all of 1574 their frags and will still need the local symbol frag 1575 information. These ports can set 1576 TC_FINALIZE_SYMS_BEFORE_SIZE_SEG to 0. */ 1577 finalize_syms = TC_FINALIZE_SYMS_BEFORE_SIZE_SEG; 1578 1538 1579 bfd_map_over_sections (stdoutput, size_seg, (char *) 0); 1539 1580 #else … … 1541 1582 #endif /* BFD_ASSEMBLER */ 1542 1583 1543 #if defined (BFD_ASSEMBLER) && defined (OBJ_COFF) && defined (TE_GO32) 1544 /* Now that the segments have their final sizes, run through the 1545 sections and set their vma and lma. !BFD gas sets them, and BFD gas 1546 should too. Currently, only DJGPP uses this code, but other 1547 COFF targets may need to execute this too. */ 1548 bfd_map_over_sections (stdoutput, set_segment_vma, (char *) 0); 1584 /* Relaxation has completed. Freeze all syms. */ 1585 finalize_syms = 1; 1586 1587 #ifdef md_post_relax_hook 1588 md_post_relax_hook; 1549 1589 #endif 1550 1590 … … 1600 1640 || fragP->fr_next == data_frag_root 1601 1641 #endif 1602 || (( fragP->fr_next->fr_address - fragP->fr_address)1642 || ((offsetT) (fragP->fr_next->fr_address - fragP->fr_address) 1603 1643 == (fragP->fr_fix + fragP->fr_offset * fragP->fr_var)))) 1604 1644 abort (); … … 1695 1735 /* This is the offset from ??? to table_ptr+0. */ 1696 1736 to_addr = table_addr - S_GET_VALUE (lie->sub); 1697 #ifdef BFD_ASSEMBLER1698 to_addr -= symbol_get_frag (lie->sub)->fr_address;1699 #endif1700 1737 #ifdef TC_CHECK_ADJUSTED_BROKEN_DOT_WORD 1701 1738 TC_CHECK_ADJUSTED_BROKEN_DOT_WORD (to_addr, lie); … … 1714 1751 from_addr = table_addr; 1715 1752 to_addr = S_GET_VALUE (lie->add) + lie->addnum; 1716 #ifdef BFD_ASSEMBLER1717 to_addr += symbol_get_frag (lie->add)->fr_address;1718 #endif1719 1753 md_create_long_jump (table_ptr, from_addr, to_addr, lie->dispfrag, 1720 1754 lie->add); … … 1834 1868 1835 1869 #ifdef BFD_HEADERS 1836 bfd_seek (stdoutput, 0, 0);1837 bfd_ write (the_object_file, 1,object_file_size, stdoutput);1870 bfd_seek (stdoutput, (file_ptr) 0, 0); 1871 bfd_bwrite (the_object_file, (bfd_size_type) object_file_size, stdoutput); 1838 1872 #else 1839 1873 … … 1859 1893 1860 1894 for (symp = symbol_rootP; symp; symp = symbol_next (symp)) 1861 resolve_symbol_value (symp , 1);1895 resolve_symbol_value (symp); 1862 1896 } 1863 1897 resolve_local_symbol_values (); … … 1873 1907 1874 1908 bfd_map_over_sections (stdoutput, adjust_reloc_syms, (char *) 0); 1909 1910 #ifdef tc_frob_file_before_fix 1911 tc_frob_file_before_fix (); 1912 #endif 1913 #ifdef obj_frob_file_before_fix 1914 obj_frob_file_before_fix (); 1915 #endif 1916 1917 bfd_map_over_sections (stdoutput, fix_segment, (char *) 0); 1875 1918 1876 1919 /* Set up symbol table, and write it out. */ … … 1901 1944 label name. */ 1902 1945 if (name2 != name && ! S_IS_DEFINED (symp)) 1903 as_bad (_("local label %sis not defined"), name2);1946 as_bad (_("local label `%s' is not defined"), name2); 1904 1947 } 1905 1948 … … 1907 1950 more symbols. They'll probably only be section symbols, 1908 1951 but they'll still need to have the values computed. */ 1909 resolve_symbol_value (symp , 1);1952 resolve_symbol_value (symp); 1910 1953 1911 1954 /* Skip symbols which were equated to undefined or common 1912 1955 symbols. */ 1913 if (symbol_equated_p (symp) 1914 && (! S_IS_DEFINED (symp) || S_IS_COMMON (symp))) 1956 if (symbol_equated_reloc_p (symp)) 1915 1957 { 1916 1958 symbol_remove (symp, &symbol_rootP, &symbol_lastP); … … 1944 1986 and symbols that the frob_symbol macros told us to punt, 1945 1987 but we keep such symbols if they are used in relocs. */ 1946 if ((! EMIT_SECTION_SYMBOLS 1947 && symbol_section_p (symp)) 1988 if (symp == abs_section_sym 1989 || (! EMIT_SECTION_SYMBOLS 1990 && symbol_section_p (symp)) 1948 1991 /* Note that S_IS_EXTERN and S_IS_LOCAL are not always 1949 1992 opposites. Sometimes the former checks flags and the 1950 1993 latter examines the name... */ 1951 1994 || (!S_IS_EXTERN (symp) 1952 && ( S_IS_LOCAL (symp) || punt)1995 && (punt || S_IS_LOCAL (symp)) 1953 1996 && ! symbol_used_in_reloc_p (symp))) 1954 1997 { … … 1964 2007 if (! symbol_resolved_p (symp)) 1965 2008 { 1966 as_bad (_("can't resolve value for symbol \"%s\""),2009 as_bad (_("can't resolve value for symbol `%s'"), 1967 2010 S_GET_NAME (symp)); 1968 2011 symbol_mark_resolved (symp); … … 2058 2101 know (sym_frag != NULL); 2059 2102 #endif 2060 know ( !(S_GET_SEGMENT (symbolP) == absolute_section)2103 know (S_GET_SEGMENT (symbolP) != absolute_section 2061 2104 || sym_frag == &zero_address_frag); 2062 target += S_GET_VALUE (symbolP) + sym_frag->fr_address;2105 target += S_GET_VALUE (symbolP); 2063 2106 2064 2107 /* If frag has yet to be reached on this pass, … … 2158 2201 addresses. */ 2159 2202 2160 void 2203 int 2161 2204 relax_segment (segment_frag_root, segment) 2162 2205 struct frag *segment_frag_root; … … 2165 2208 register struct frag *fragP; 2166 2209 register relax_addressT address; 2210 int ret; 2211 2167 2212 #if !defined (MANY_SEGMENTS) && !defined (BFD_ASSEMBLER) 2168 2213 know (segment == SEG_DATA || segment == SEG_TEXT || segment == SEG_BSS); … … 2197 2242 if (offset % fragP->fr_var != 0) 2198 2243 { 2199 as_bad (_("alignment padding (%lu bytes) not a multiple of %ld"), 2200 (unsigned long) offset, (long) fragP->fr_var); 2244 as_bad_where (fragP->fr_file, fragP->fr_line, 2245 _("alignment padding (%lu bytes) not a multiple of %ld"), 2246 (unsigned long) offset, (long) fragP->fr_var); 2201 2247 offset -= (offset % fragP->fr_var); 2202 2248 } … … 2212 2258 2213 2259 case rs_machine_dependent: 2260 /* If fr_symbol is an expression, this call to 2261 resolve_symbol_value sets up the correct segment, which will 2262 likely be needed in md_estimate_size_before_relax. */ 2263 if (fragP->fr_symbol) 2264 resolve_symbol_value (fragP->fr_symbol); 2265 2214 2266 address += md_estimate_size_before_relax (fragP, segment); 2215 2267 break; … … 2298 2350 continue; 2299 2351 2300 offset = (symbol_get_frag (lie->add)->fr_address 2301 + S_GET_VALUE (lie->add) 2352 offset = (S_GET_VALUE (lie->add) 2302 2353 + lie->addnum 2303 - (symbol_get_frag (lie->sub)->fr_address 2304 + S_GET_VALUE (lie->sub))); 2354 - S_GET_VALUE (lie->sub)); 2305 2355 if (offset <= -32768 || offset >= 32767) 2306 2356 { … … 2309 2359 char buf[50]; 2310 2360 sprint_value (buf, (addressT) lie->addnum); 2311 as_warn (_(".word %s-%s+%s didn't fit"), 2312 S_GET_NAME (lie->add), 2313 S_GET_NAME (lie->sub), 2314 buf); 2361 as_warn_where (fragP->fr_file, fragP->fr_line, 2362 _(".word %s-%s+%s didn't fit"), 2363 S_GET_NAME (lie->add), 2364 S_GET_NAME (lie->sub), 2365 buf); 2315 2366 } 2316 2367 lie->added = 1; … … 2377 2428 || (symbolP->sy_frag == &zero_address_frag)); 2378 2429 #endif 2379 target += (S_GET_VALUE (symbolP) 2380 + symbol_get_frag (symbolP)->fr_address); 2381 } /* if we have a symbol */ 2430 /* Convert from an actual address to an octet offset 2431 into the section. Here it is assumed that the 2432 section's VMA is zero, and can omit subtracting it 2433 from the symbol's value to get the address offset. */ 2434 know (S_GET_SECTION (symbolP)->vma == 0); 2435 target += S_GET_VALUE (symbolP) * OCTETS_PER_BYTE; 2436 } 2382 2437 2383 2438 know (fragP->fr_next); … … 2390 2445 .org backwards. */ 2391 2446 as_bad_where (fragP->fr_file, fragP->fr_line, 2392 _("attempt to .org backwards ignored"));2447 _("attempt to .org backwards")); 2393 2448 2394 2449 /* We've issued an error message. Change the … … 2407 2462 2408 2463 case rs_space: 2464 growth = 0; 2409 2465 if (symbolP) 2410 2466 { 2411 growth = S_GET_VALUE (symbolP); 2412 if (symbol_get_frag (symbolP) != &zero_address_frag 2467 offsetT amount; 2468 2469 amount = S_GET_VALUE (symbolP); 2470 if (S_GET_SEGMENT (symbolP) != absolute_section 2413 2471 || S_IS_COMMON (symbolP) 2414 2472 || ! S_IS_DEFINED (symbolP)) 2415 as_bad_where (fragP->fr_file, fragP->fr_line,2416 _(".space specifies non-absolute value"));2417 fragP->fr_symbol = 0;2418 if (growth < 0)2419 2473 { 2420 as_warn (_(".space or .fill with negative value, ignored")); 2421 growth = 0; 2474 as_bad_where (fragP->fr_file, fragP->fr_line, 2475 _(".space specifies non-absolute value")); 2476 /* Prevent repeat of this error message. */ 2477 fragP->fr_symbol = 0; 2422 2478 } 2479 else if (amount < 0) 2480 { 2481 as_warn_where (fragP->fr_file, fragP->fr_line, 2482 _(".space or .fill with negative value, ignored")); 2483 fragP->fr_symbol = 0; 2484 } 2485 else 2486 growth = (was_address + fragP->fr_fix + amount 2487 - fragP->fr_next->fr_address); 2423 2488 } 2424 else2425 growth = 0;2426 2489 break; 2427 2490 … … 2443 2506 int size; 2444 2507 2445 value = resolve_symbol_value (fragP->fr_symbol , 0);2508 value = resolve_symbol_value (fragP->fr_symbol); 2446 2509 size = sizeof_leb128 (value, fragP->fr_subtype); 2447 2510 growth = size - fragP->fr_offset; … … 2472 2535 } /* do_relax */ 2473 2536 2474 /* We now have valid fr_address'es for each frag. */ 2475 2476 /* All fr_address's are correct, relative to their own segment. 2477 We have made all the fixS we will ever make. */ 2537 ret = 0; 2538 for (fragP = segment_frag_root; fragP; fragP = fragP->fr_next) 2539 if (fragP->last_fr_address != fragP->fr_address) 2540 { 2541 fragP->last_fr_address = fragP->fr_address; 2542 ret = 1; 2543 } 2544 return ret; 2478 2545 } 2479 2546 2480 2547 #if defined (BFD_ASSEMBLER) || (!defined (BFD) && !defined (OBJ_VMS)) 2481 2482 #ifndef TC_RELOC_RTSYM_LOC_FIXUP2483 #define TC_RELOC_RTSYM_LOC_FIXUP(X) (1)2484 #endif2485 2548 2486 2549 /* fixup_segment() … … 2489 2552 handled now. (These consist of fixS where we have since discovered 2490 2553 the value of a symbol, or the address of the frag involved.) 2491 For each one, call md_apply_fix to put the fix into the frag data.2554 For each one, call md_apply_fix3 to put the fix into the frag data. 2492 2555 2493 2556 Result is a count of how many relocation structs will be needed to … … 2496 2559 2497 2560 static long 2498 fixup_segment (fixP, this_segment _type)2499 registerfixS *fixP;2500 segT this_segment _type; /* N_TYPE bits for segment. */2561 fixup_segment (fixP, this_segment) 2562 fixS *fixP; 2563 segT this_segment; 2501 2564 { 2502 2565 long seg_reloc_count = 0; 2503 symbolS *add_symbolP;2504 symbolS *sub_symbolP;2505 2566 valueT add_number; 2506 int size;2507 char *place;2508 long where;2509 int pcrel, plt;2510 2567 fragS *fragP; 2511 2568 segT add_symbol_segment = absolute_section; 2512 2569 2570 if (fixP != NULL && abs_section_sym == NULL) 2571 { 2572 #ifndef BFD_ASSEMBLER 2573 abs_section_sym = &abs_symbol; 2574 #else 2575 abs_section_sym = section_symbol (absolute_section); 2576 #endif 2577 } 2578 2513 2579 /* If the linker is doing the relaxing, we must not do any fixups. 2514 2580 2515 Well, strictly speaking that's not true -- we could do any that are 2516 PC-relative and don't cross regions that could change size. And for the 2517 i960 (the only machine for which we've got a relaxing linker right now), 2518 we might be able to turn callx/callj into bal anyways in cases where we 2519 know the maximum displacement. */ 2520 if (linkrelax && TC_LINKRELAX_FIXUP (this_segment_type)) 2581 Well, strictly speaking that's not true -- we could do any that 2582 are PC-relative and don't cross regions that could change size. 2583 And for the i960 we might be able to turn callx/callj into bal 2584 anyways in cases where we know the maximum displacement. */ 2585 if (linkrelax && TC_LINKRELAX_FIXUP (this_segment)) 2521 2586 { 2522 2587 for (; fixP; fixP = fixP->fx_next) 2523 seg_reloc_count++; 2588 if (!fixP->fx_done) 2589 { 2590 if (fixP->fx_addsy == NULL) 2591 { 2592 /* There was no symbol required by this relocation. 2593 However, BFD doesn't really handle relocations 2594 without symbols well. So fake up a local symbol in 2595 the absolute section. */ 2596 fixP->fx_addsy = abs_section_sym; 2597 } 2598 symbol_mark_used_in_reloc (fixP->fx_addsy); 2599 if (fixP->fx_subsy != NULL) 2600 symbol_mark_used_in_reloc (fixP->fx_subsy); 2601 seg_reloc_count++; 2602 } 2524 2603 TC_ADJUST_RELOC_COUNT (fixP, seg_reloc_count); 2525 2604 return seg_reloc_count; … … 2535 2614 fragP = fixP->fx_frag; 2536 2615 know (fragP); 2537 where = fixP->fx_where;2538 place = fragP->fr_literal + where;2539 size = fixP->fx_size;2540 add_symbolP = fixP->fx_addsy;2541 2616 #ifdef TC_VALIDATE_FIX 2542 TC_VALIDATE_FIX (fixP, this_segment_type, skip); 2543 #endif 2544 sub_symbolP = fixP->fx_subsy; 2617 TC_VALIDATE_FIX (fixP, this_segment, skip); 2618 #endif 2545 2619 add_number = fixP->fx_offset; 2546 pcrel = fixP->fx_pcrel; 2547 plt = fixP->fx_plt; 2548 2549 if (add_symbolP != NULL 2550 && symbol_mri_common_p (add_symbolP)) 2620 2621 if (fixP->fx_addsy != NULL 2622 && symbol_mri_common_p (fixP->fx_addsy)) 2551 2623 { 2552 know ( add_symbolP->sy_value.X_op == O_symbol);2553 add_number += S_GET_VALUE ( add_symbolP);2624 know (fixP->fx_addsy->sy_value.X_op == O_symbol); 2625 add_number += S_GET_VALUE (fixP->fx_addsy); 2554 2626 fixP->fx_offset = add_number; 2555 add_symbolP = fixP->fx_addsy =2556 symbol_get_value_expression (add_symbolP)->X_add_symbol;2627 fixP->fx_addsy 2628 = symbol_get_value_expression (fixP->fx_addsy)->X_add_symbol; 2557 2629 } 2558 2630 2559 if ( add_symbolP)2560 add_symbol_segment = S_GET_SEGMENT ( add_symbolP);2561 2562 if ( sub_symbolP)2631 if (fixP->fx_addsy != NULL) 2632 add_symbol_segment = S_GET_SEGMENT (fixP->fx_addsy); 2633 2634 if (fixP->fx_subsy != NULL) 2563 2635 { 2564 resolve_symbol_value (sub_symbolP, 1); 2565 if (add_symbolP == NULL || add_symbol_segment == absolute_section) 2636 segT sub_symbol_segment; 2637 resolve_symbol_value (fixP->fx_subsy); 2638 sub_symbol_segment = S_GET_SEGMENT (fixP->fx_subsy); 2639 if (fixP->fx_addsy != NULL 2640 && sub_symbol_segment == add_symbol_segment 2641 && !TC_FORCE_RELOCATION_SUB_SAME (fixP, add_symbol_segment)) 2566 2642 { 2567 if (add_symbolP != NULL) 2568 { 2569 add_number += S_GET_VALUE (add_symbolP); 2570 add_symbolP = NULL; 2571 fixP->fx_addsy = NULL; 2572 } 2573 2574 /* It's just -sym. */ 2575 if (S_GET_SEGMENT (sub_symbolP) == absolute_section) 2576 { 2577 add_number -= S_GET_VALUE (sub_symbolP); 2578 fixP->fx_subsy = NULL; 2579 } 2580 else if (pcrel 2581 && S_GET_SEGMENT (sub_symbolP) == this_segment_type) 2582 { 2583 /* Should try converting to a constant. */ 2584 goto bad_sub_reloc; 2585 } 2586 else 2587 bad_sub_reloc: 2588 as_bad_where (fixP->fx_file, fixP->fx_line, 2589 _("Negative of non-absolute symbol %s"), 2590 S_GET_NAME (sub_symbolP)); 2643 add_number += S_GET_VALUE (fixP->fx_addsy); 2644 add_number -= S_GET_VALUE (fixP->fx_subsy); 2645 fixP->fx_offset = add_number; 2646 /* If the back-end code has selected a pc-relative 2647 reloc, adjust the value to be pc-relative. */ 2648 if (1 2649 #ifdef TC_M68K 2650 /* See the comment below about 68k weirdness. */ 2651 && 0 2652 #endif 2653 && fixP->fx_pcrel) 2654 add_number -= MD_PCREL_FROM_SECTION (fixP, this_segment); 2655 fixP->fx_addsy = NULL; 2656 fixP->fx_subsy = NULL; 2657 fixP->fx_pcrel = 0; 2591 2658 } 2592 else if ( S_GET_SEGMENT (sub_symbolP) == add_symbol_segment2593 && SEG_NORMAL (add_symbol_segment))2659 else if (sub_symbol_segment == absolute_section 2660 && !TC_FORCE_RELOCATION_SUB_ABS (fixP)) 2594 2661 { 2595 /* Difference of 2 symbols from same segment. 2596 Can't make difference of 2 undefineds: 'value' means 2597 something different for N_UNDF. */ 2598 #ifdef TC_I960 2599 /* Makes no sense to use the difference of 2 arbitrary symbols 2600 as the target of a call instruction. */ 2601 if (fixP->fx_tcbit) 2602 as_bad_where (fixP->fx_file, fixP->fx_line, 2603 _("callj to difference of 2 symbols")); 2604 #endif /* TC_I960 */ 2605 add_number += S_GET_VALUE (add_symbolP) - 2606 S_GET_VALUE (sub_symbolP); 2607 2608 add_symbolP = NULL; 2609 pcrel = 0; /* No further pcrel processing. */ 2610 2611 /* Let the target machine make the final determination 2612 as to whether or not a relocation will be needed to 2613 handle this fixup. */ 2614 if (!TC_FORCE_RELOCATION_SECTION (fixP, this_segment_type)) 2615 { 2616 fixP->fx_pcrel = 0; 2617 fixP->fx_addsy = NULL; 2618 fixP->fx_subsy = NULL; 2619 } 2662 add_number -= S_GET_VALUE (fixP->fx_subsy); 2663 fixP->fx_offset = add_number; 2664 fixP->fx_subsy = NULL; 2620 2665 } 2621 else 2666 else if (sub_symbol_segment == this_segment 2667 && !TC_FORCE_RELOCATION_SUB_LOCAL (fixP)) 2622 2668 { 2623 /* Different segments in subtraction. */ 2624 know (!(S_IS_EXTERNAL (sub_symbolP) 2625 && (S_GET_SEGMENT (sub_symbolP) == absolute_section))); 2626 2627 if ((S_GET_SEGMENT (sub_symbolP) == absolute_section)) 2628 add_number -= S_GET_VALUE (sub_symbolP); 2629 2630 #ifdef DIFF_EXPR_OK 2631 else if (S_GET_SEGMENT (sub_symbolP) == this_segment_type 2632 #if 0 2633 /* Do this even if it's already described as 2634 pc-relative. For example, on the m68k, an 2635 operand of "pc@(foo-.-2)" should address 2636 "foo" in a pc-relative mode. */ 2637 && pcrel 2638 #endif 2639 ) 2640 { 2641 /* Make it pc-relative. */ 2642 add_number += (MD_PCREL_FROM_SECTION (fixP, this_segment_type) 2643 - S_GET_VALUE (sub_symbolP)); 2644 pcrel = 1; 2645 fixP->fx_pcrel = 1; 2646 sub_symbolP = 0; 2647 fixP->fx_subsy = 0; 2648 } 2649 #endif 2650 #ifdef UNDEFINED_DIFFERENCE_OK 2651 /* The PA needs this for PIC code generation. We basically 2652 don't want to do anything if we have the difference of two 2653 symbols at this point. */ 2654 else if (1) 2655 { 2656 /* Leave it alone. */ 2657 } 2658 #endif 2659 #ifdef BFD_ASSEMBLER 2660 else if (fixP->fx_r_type == BFD_RELOC_GPREL32 2661 || fixP->fx_r_type == BFD_RELOC_GPREL16) 2662 { 2663 /* Leave it alone. */ 2664 } 2665 #endif 2666 else 2667 { 2668 char buf[50]; 2669 sprint_value (buf, fragP->fr_address + where); 2670 as_bad_where (fixP->fx_file, fixP->fx_line, 2671 _("Subtraction of two symbols in different sections \"%s\" {%s section} - \"%s\" {%s section} at file address %s."), 2672 S_GET_NAME (add_symbolP), 2673 segment_name (S_GET_SEGMENT (add_symbolP)), 2674 S_GET_NAME (sub_symbolP), 2675 segment_name (S_GET_SEGMENT (sub_symbolP)), 2676 buf); 2677 } 2669 add_number -= S_GET_VALUE (fixP->fx_subsy); 2670 fixP->fx_offset = (add_number + fixP->fx_dot_value 2671 + fixP->fx_frag->fr_address); 2672 2673 /* Make it pc-relative. If the back-end code has not 2674 selected a pc-relative reloc, cancel the adjustment 2675 we do later on all pc-relative relocs. */ 2676 if (0 2677 #ifdef TC_M68K 2678 /* Do this for m68k even if it's already described 2679 as pc-relative. On the m68k, an operand of 2680 "pc@(foo-.-2)" should address "foo" in a 2681 pc-relative mode. */ 2682 || 1 2683 #endif 2684 || !fixP->fx_pcrel) 2685 add_number += MD_PCREL_FROM_SECTION (fixP, this_segment); 2686 fixP->fx_subsy = NULL; 2687 fixP->fx_pcrel = 1; 2688 } 2689 else if (!TC_VALIDATE_FIX_SUB (fixP)) 2690 { 2691 as_bad_where (fixP->fx_file, fixP->fx_line, 2692 _("can't resolve `%s' {%s section} - `%s' {%s section}"), 2693 fixP->fx_addsy ? S_GET_NAME (fixP->fx_addsy) : "0", 2694 segment_name (add_symbol_segment), 2695 S_GET_NAME (fixP->fx_subsy), 2696 segment_name (sub_symbol_segment)); 2678 2697 } 2679 2698 } 2680 2699 2681 if ( add_symbolP)2700 if (fixP->fx_addsy) 2682 2701 { 2683 if (add_symbol_segment == this_segment _type && pcrel && !plt2684 && TC_RELOC_RTSYM_LOC_FIXUP(fixP))2702 if (add_symbol_segment == this_segment 2703 && !TC_FORCE_RELOCATION_LOCAL (fixP)) 2685 2704 { 2686 2705 /* This fixup was made when the symbol's segment was 2687 2706 SEG_UNKNOWN, but it is now in the local segment. 2688 2707 So we know how to do the address without relocation. */ 2689 #ifdef TC_I960 2690 /* reloc_callj() may replace a 'call' with a 'calls' or a 2691 'bal', in which cases it modifies *fixP as appropriate. 2692 In the case of a 'calls', no further work is required, 2693 and *fixP has been set up to make the rest of the code 2694 below a no-op. */ 2695 reloc_callj (fixP); 2696 #endif /* TC_I960 */ 2697 2698 add_number += S_GET_VALUE (add_symbolP); 2699 add_number -= MD_PCREL_FROM_SECTION (fixP, this_segment_type); 2700 /* Lie. Don't want further pcrel processing. */ 2701 pcrel = 0; 2702 2703 /* Let the target machine make the final determination 2704 as to whether or not a relocation will be needed to 2705 handle this fixup. */ 2706 if (!TC_FORCE_RELOCATION (fixP)) 2707 { 2708 fixP->fx_pcrel = 0; 2709 fixP->fx_addsy = NULL; 2710 } 2708 add_number += S_GET_VALUE (fixP->fx_addsy); 2709 fixP->fx_offset = add_number; 2710 if (fixP->fx_pcrel) 2711 add_number -= MD_PCREL_FROM_SECTION (fixP, this_segment); 2712 fixP->fx_addsy = NULL; 2713 fixP->fx_pcrel = 0; 2711 2714 } 2712 else 2715 else if (add_symbol_segment == absolute_section 2716 && !TC_FORCE_RELOCATION_ABS (fixP)) 2713 2717 { 2714 if (add_symbol_segment == absolute_section 2715 && ! pcrel) 2716 { 2717 #ifdef TC_I960 2718 /* See comment about reloc_callj() above. */ 2719 reloc_callj (fixP); 2720 #endif /* TC_I960 */ 2721 add_number += S_GET_VALUE (add_symbolP); 2722 2723 /* Let the target machine make the final determination 2724 as to whether or not a relocation will be needed to 2725 handle this fixup. */ 2726 2727 if (!TC_FORCE_RELOCATION (fixP)) 2728 { 2729 fixP->fx_addsy = NULL; 2730 add_symbolP = NULL; 2731 } 2732 } 2733 else if (add_symbol_segment == undefined_section 2718 add_number += S_GET_VALUE (fixP->fx_addsy); 2719 fixP->fx_offset = add_number; 2720 fixP->fx_addsy = NULL; 2721 } 2722 else if (add_symbol_segment != undefined_section 2734 2723 #ifdef BFD_ASSEMBLER 2735 || bfd_is_com_section (add_symbol_segment) 2736 #endif 2737 ) 2738 { 2739 #ifdef TC_I960 2740 if ((int) fixP->fx_bit_fixP == 13) 2741 { 2742 /* This is a COBR instruction. They have only a 2743 13-bit displacement and are only to be used 2744 for local branches: flag as error, don't generate 2745 relocation. */ 2746 as_bad_where (fixP->fx_file, fixP->fx_line, 2747 _("can't use COBR format with external label")); 2748 fixP->fx_addsy = NULL; 2749 fixP->fx_done = 1; 2750 continue; 2751 } /* COBR. */ 2752 #endif /* TC_I960 */ 2753 2754 #ifdef OBJ_COFF 2755 #ifdef TE_I386AIX 2756 if (S_IS_COMMON (add_symbolP)) 2757 add_number += S_GET_VALUE (add_symbolP); 2758 #endif /* TE_I386AIX */ 2759 #endif /* OBJ_COFF */ 2760 ++seg_reloc_count; 2761 } 2762 else 2763 { 2764 seg_reloc_count++; 2765 if (TC_FIX_ADJUSTABLE (fixP)) 2766 add_number += S_GET_VALUE (add_symbolP); 2767 } 2724 && ! bfd_is_com_section (add_symbol_segment) 2725 #endif 2726 && MD_APPLY_SYM_VALUE (fixP)) 2727 add_number += S_GET_VALUE (fixP->fx_addsy); 2728 } 2729 2730 if (fixP->fx_pcrel) 2731 { 2732 add_number -= MD_PCREL_FROM_SECTION (fixP, this_segment); 2733 if (!fixP->fx_done && fixP->fx_addsy == NULL) 2734 { 2735 /* There was no symbol required by this relocation. 2736 However, BFD doesn't really handle relocations 2737 without symbols well. So fake up a local symbol in 2738 the absolute section. */ 2739 fixP->fx_addsy = abs_section_sym; 2768 2740 } 2769 2741 } 2770 2742 2771 if (pcrel) 2772 { 2773 add_number -= MD_PCREL_FROM_SECTION (fixP, this_segment_type); 2774 if (add_symbolP == 0) 2775 { 2776 #ifndef BFD_ASSEMBLER 2777 fixP->fx_addsy = &abs_symbol; 2778 #else 2779 fixP->fx_addsy = section_symbol (absolute_section); 2780 #endif 2781 symbol_mark_used_in_reloc (fixP->fx_addsy); 2782 ++seg_reloc_count; 2783 } 2784 } 2743 if (!fixP->fx_done) 2744 md_apply_fix3 (fixP, &add_number, this_segment); 2785 2745 2786 2746 if (!fixP->fx_done) 2787 2747 { 2788 #ifdef MD_APPLY_FIX3 2789 md_apply_fix3 (fixP, &add_number, this_segment_type); 2790 #else 2791 #ifdef BFD_ASSEMBLER 2792 md_apply_fix (fixP, &add_number); 2793 #else 2794 md_apply_fix (fixP, add_number); 2795 #endif 2796 #endif 2797 2798 #ifndef TC_HANDLES_FX_DONE 2799 /* If the tc-* files haven't been converted, assume it's handling 2800 it the old way, where a null fx_addsy means that the fix has 2801 been applied completely, and no further work is needed. */ 2802 if (fixP->fx_addsy == 0 && fixP->fx_pcrel == 0) 2803 fixP->fx_done = 1; 2804 #endif 2748 ++seg_reloc_count; 2749 if (fixP->fx_addsy == NULL) 2750 fixP->fx_addsy = abs_section_sym; 2751 symbol_mark_used_in_reloc (fixP->fx_addsy); 2752 if (fixP->fx_subsy != NULL) 2753 symbol_mark_used_in_reloc (fixP->fx_subsy); 2805 2754 } 2806 2755 2807 if (!fixP->fx_bit_fixP && !fixP->fx_no_overflow && size >0)2756 if (!fixP->fx_bit_fixP && !fixP->fx_no_overflow && fixP->fx_size != 0) 2808 2757 { 2809 if ( (size_t)size < sizeof (valueT))2758 if (fixP->fx_size < sizeof (valueT)) 2810 2759 { 2811 2760 valueT mask; … … 2813 2762 mask = 0; 2814 2763 mask--; /* Set all bits to one. */ 2815 mask <<= size * 8 - (fixP->fx_signed ? 1 : 0);2764 mask <<= fixP->fx_size * 8 - (fixP->fx_signed ? 1 : 0); 2816 2765 if ((add_number & mask) != 0 && (add_number & mask) != mask) 2817 2766 { 2818 2767 char buf[50], buf2[50]; 2819 sprint_value (buf, fragP->fr_address + where);2768 sprint_value (buf, fragP->fr_address + fixP->fx_where); 2820 2769 if (add_number > 1000) 2821 2770 sprint_value (buf2, add_number); … … 2823 2772 sprintf (buf2, "%ld", (long) add_number); 2824 2773 as_bad_where (fixP->fx_file, fixP->fx_line, 2825 _(" Value of %s too large for field of %d bytes at %s"),2826 buf2, size, buf);2774 _("value of %s too large for field of %d bytes at %s"), 2775 buf2, fixP->fx_size, buf); 2827 2776 } /* Generic error checking. */ 2828 2777 } … … 2832 2781 catch over-large switches generated by gcc on the 68k. */ 2833 2782 if (!flag_signed_overflow_ok 2834 && size == 22783 && fixP->fx_size == 2 2835 2784 && add_number > 0x7fff) 2836 2785 as_bad_where (fixP->fx_file, fixP->fx_line, 2837 _(" Signed .word overflow; switch may be too large; %ld at 0x%lx"),2786 _("signed .word overflow; switch may be too large; %ld at 0x%lx"), 2838 2787 (long) add_number, 2839 ( unsigned long) (fragP->fr_address +where));2788 (long) (fragP->fr_address + fixP->fx_where)); 2840 2789 #endif 2841 2790 } /* Not a bit fix. */ … … 2863 2812 int n; 2864 2813 { 2865 if ( (size_t) n > sizeof (val) ||n <= 0)2814 if (n <= 0) 2866 2815 abort (); 2867 2816 while (n--) … … 2878 2827 int n; 2879 2828 { 2880 if ( (size_t) n > sizeof (val) ||n <= 0)2829 if (n <= 0) 2881 2830 abort (); 2882 2831 while (n--) -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.