Changeset 618 for trunk/src/binutils/gas/write.c
- Timestamp:
- Aug 16, 2003, 11:33:53 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/binutils/gas/write.c
-
Property cvs2svn:cvs-rev
changed from
1.2
to1.3
r617 r618 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 #ifndef __EMX__ 860 /* UGLY HACK: FOR SOME REASON IT DOESN'T WORK WITH EMX, 861 BUT IT LOOKS LIKE IT IS LIBBFD FAULT! LET'S WAIT TILL IT GETS FIXED. */ 862 /* We can never adjust a reloc against a weak symbol. If we 863 did, and the weak symbol was overridden by a real symbol 864 somewhere else, then our relocation would be pointing at 865 the wrong area of memory. */ 866 if (S_IS_WEAK (sym)) 867 { 868 symbol_mark_used_in_reloc (fixp->fx_addsy); 869 goto done; 870 } 871 #endif 872 #endif 873 874 /* Is there some other reason we can't adjust this one? (E.g., 875 call/bal links in i960-bout symbols.) */ 876 #ifdef obj_fix_adjustable 877 if (! obj_fix_adjustable (fixp)) 878 { 879 symbol_mark_used_in_reloc (fixp->fx_addsy); 880 goto done; 881 } 882 #endif 883 884 /* Is there some other (target cpu dependent) reason we can't adjust 885 this one? (E.g. relocations involving function addresses on 886 the PA. */ 887 #ifdef tc_fix_adjustable 888 if (! tc_fix_adjustable (fixp)) 889 { 890 symbol_mark_used_in_reloc (fixp->fx_addsy); 891 goto done; 892 } 893 #endif 894 895 /* If the section symbol isn't going to be output, the relocs 896 at least should still work. If not, figure out what to do 897 when we run into that case. 898 899 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 900 893 than using symsec, because S_GET_VALUE may wind up changing 901 894 the section when it calls resolve_symbol_value. */ 902 895 fixp->fx_offset += S_GET_VALUE (sym); 903 896 fixp->fx_addsy = section_symbol (S_GET_SEGMENT (sym)); 904 symbol_mark_used_in_reloc (fixp->fx_addsy);905 897 #ifdef DEBUG5 906 898 fprintf (stderr, "\nadjusted fixup:\n"); 907 899 print_fixup (fixp); 908 900 #endif 909 910 done:911 ;912 901 } 913 #if 1 /* def RELOC_REQUIRES_SYMBOL */914 else915 {916 /* There was no symbol required by this relocation. However,917 BFD doesn't really handle relocations without symbols well.918 (At least, the COFF support doesn't.) So for now we fake up919 a local symbol in the absolute section. */920 921 fixp->fx_addsy = section_symbol (absolute_section);922 #if 0923 fixp->fx_addsy->sy_used_in_reloc = 1;924 #endif925 }926 #endif927 902 928 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); 929 915 } 930 916 … … 947 933 return; 948 934 949 fixup_segment (seginfo->fix_root, sec);950 951 935 n = 0; 952 936 for (fixp = seginfo->fix_root; fixp; fixp = fixp->fx_next) … … 972 956 973 957 /* If this is an undefined symbol which was equated to another 974 symbol, then usegenerate the reloc against the latter symbol958 symbol, then generate the reloc against the latter symbol 975 959 rather than the former. */ 976 960 sym = fixp->fx_addsy; 977 while (symbol_equated_p (sym) 978 && (! S_IS_DEFINED (sym) || S_IS_COMMON (sym))) 961 while (symbol_equated_reloc_p (sym)) 979 962 { 980 963 symbolS *n; … … 1013 996 break; 1014 997 case bfd_reloc_overflow: 1015 as_bad_where (fixp->fx_file, fixp->fx_line, _("relocation overflow")); 998 as_bad_where (fixp->fx_file, fixp->fx_line, 999 _("relocation overflow")); 1016 1000 break; 1017 1001 case bfd_reloc_outofrange: 1018 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")); 1019 1004 break; 1020 1005 default: … … 1033 1018 { 1034 1019 arelent **reloc; 1035 char *data;1036 1020 bfd_reloc_status_type s; 1037 1021 symbolS *sym; … … 1048 1032 rather than the former. */ 1049 1033 sym = fixp->fx_addsy; 1050 while (symbol_equated_p (sym) 1051 && (! S_IS_DEFINED (sym) || S_IS_COMMON (sym))) 1052 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 } 1053 1046 fixp->fx_addsy = sym; 1054 1047 … … 1060 1053 assert (i <= n); 1061 1054 } 1062 data = fixp->fx_frag->fr_literal + fixp->fx_where;1063 1055 if (fixp->fx_where + fixp->fx_size 1064 1056 > fixp->fx_frag->fr_fix + fixp->fx_frag->fr_offset) … … 1079 1071 _("relocation overflow")); 1080 1072 break; 1073 case bfd_reloc_outofrange: 1074 as_bad_where (fixp->fx_file, fixp->fx_line, 1075 _("relocation out of range")); 1076 break; 1081 1077 default: 1082 as_fatal (_("%s:%u: bad return from bfd_install_relocation "),1083 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); 1084 1080 } 1085 1081 } … … 1164 1160 f->fr_literal, (file_ptr) offset, 1165 1161 (bfd_size_type) f->fr_fix); 1166 if ( x == false)1162 if (!x) 1167 1163 { 1168 1164 bfd_perror (stdoutput->filename); … … 1188 1184 (file_ptr) offset, 1189 1185 (bfd_size_type) fill_size); 1190 if ( x == false)1186 if (!x) 1191 1187 { 1192 1188 bfd_perror (stdoutput->filename); … … 1222 1218 (stdoutput, sec, buf, (file_ptr) offset, 1223 1219 (bfd_size_type) n_per_buf * fill_size); 1224 if ( x != true)1225 as_fatal (_(" Cannot write to output file."));1220 if (!x) 1221 as_fatal (_("cannot write to output file")); 1226 1222 offset += n_per_buf * fill_size; 1227 1223 } … … 1356 1352 asymbol **asympp; 1357 1353 symbolS *symp; 1358 b oolean result;1359 extern PTR bfd_alloc PARAMS ((bfd *, size_t));1354 bfd_boolean result; 1355 extern PTR bfd_alloc PARAMS ((bfd *, bfd_size_type)); 1360 1356 1361 1357 /* Count symbols. We can't rely on a count made by the loop in … … 1369 1365 { 1370 1366 int i; 1371 1372 asympp = (asymbol **) bfd_alloc (stdoutput, 1373 nsyms * sizeof (asymbol *));1367 bfd_size_type amt = (bfd_size_type) nsyms * sizeof (asymbol *); 1368 1369 asympp = (asymbol **) bfd_alloc (stdoutput, amt); 1374 1370 symp = symbol_rootP; 1375 1371 for (i = 0; i < nsyms; i++, symp = symbol_next (symp)) … … 1382 1378 asympp = 0; 1383 1379 result = bfd_set_symtab (stdoutput, asympp, nsyms); 1384 assert (result == true);1380 assert (result); 1385 1381 symbol_table_frozen = 1; 1386 1382 } 1387 1383 #endif 1388 1389 #if defined (BFD_ASSEMBLER) && defined (OBJ_COFF) && defined (TE_GO32)1390 static void1391 set_segment_vma (abfd, sec, xxx)1392 bfd *abfd;1393 asection *sec;1394 PTR xxx ATTRIBUTE_UNUSED;1395 {1396 static bfd_vma addr = 0;1397 1398 bfd_set_section_vma (abfd, sec, addr);1399 addr += bfd_section_size (abfd, sec);1400 }1401 #endif /* BFD_ASSEMBLER && OBJ_COFF && !TE_PE */1402 1384 1403 1385 /* Finish the subsegments. After every sub-segment, we fake an … … 1408 1390 1409 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 1410 1400 #ifdef BFD_ASSEMBLER 1411 #define SUB_SEGMENT_ALIGN(SEG ) (0)1401 #define SUB_SEGMENT_ALIGN(SEG, FRCHAIN) 0 1412 1402 #else 1413 #define SUB_SEGMENT_ALIGN(SEG) (2) 1403 #define SUB_SEGMENT_ALIGN(SEG, FRCHAIN) 2 1404 #endif 1414 1405 #endif 1415 1406 #endif … … 1422 1413 for (frchainP = frchain_root; frchainP; frchainP = frchainP->frch_next) 1423 1414 { 1424 int alignment ;1415 int alignment = 0; 1425 1416 1426 1417 subseg_set (frchainP->frch_seg, frchainP->frch_subseg); … … 1429 1420 any alignment is meaningless, and, moreover, will look weird 1430 1421 if we are generating a listing. */ 1431 alignment = had_errors () ? 0 : SUB_SEGMENT_ALIGN (now_seg); 1432 1433 /* The last subsegment gets an aligment corresponding to the 1434 alignment of the section. This allows proper nop-filling 1435 at the end of code-bearing sections. */ 1436 if (!frchainP->frch_next || frchainP->frch_next->frch_seg != now_seg) 1437 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 } 1438 1442 1439 1443 if (subseg_text_p (now_seg)) … … 1472 1476 { 1473 1477 if (n_warns || n_errs) 1474 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"), 1475 1479 n_errs, n_errs == 1 ? "" : "s", 1476 1480 n_warns, n_warns == 1 ? "" : "s"); … … 1479 1483 { 1480 1484 if (n_errs) 1481 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"), 1482 1486 n_errs, n_errs == 1 ? "" : "s", 1483 1487 n_warns, n_warns == 1 ? "" : "s"); … … 1498 1502 /* Remove the sections created by gas for its own purposes. */ 1499 1503 { 1500 asection **seclist , *sec;1504 asection **seclist; 1501 1505 int i; 1502 1506 1503 1507 seclist = &stdoutput->sections; 1504 while ( seclist &&*seclist)1508 while (*seclist) 1505 1509 { 1506 sec = *seclist; 1507 while (sec == reg_section || sec == expr_section) 1510 if (*seclist == reg_section || *seclist == expr_section) 1508 1511 { 1509 sec = sec->next; 1510 *seclist = sec; 1512 bfd_section_list_remove (stdoutput, seclist); 1511 1513 stdoutput->section_count--; 1512 if (!sec)1513 break;1514 1514 } 1515 if (*seclist)1515 else 1516 1516 seclist = &(*seclist)->next; 1517 1517 } … … 1538 1538 1539 1539 #ifdef BFD_ASSEMBLER 1540 bfd_map_over_sections (stdoutput, relax_seg, (char *) 1); 1541 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 1542 1579 bfd_map_over_sections (stdoutput, size_seg, (char *) 0); 1543 1580 #else … … 1545 1582 #endif /* BFD_ASSEMBLER */ 1546 1583 1547 #if defined (BFD_ASSEMBLER) && defined (OBJ_COFF) && defined (TE_GO32) 1548 /* Now that the segments have their final sizes, run through the 1549 sections and set their vma and lma. !BFD gas sets them, and BFD gas 1550 should too. Currently, only DJGPP uses this code, but other 1551 COFF targets may need to execute this too. */ 1552 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; 1553 1589 #endif 1554 1590 … … 1604 1640 || fragP->fr_next == data_frag_root 1605 1641 #endif 1606 || (( fragP->fr_next->fr_address - fragP->fr_address)1642 || ((offsetT) (fragP->fr_next->fr_address - fragP->fr_address) 1607 1643 == (fragP->fr_fix + fragP->fr_offset * fragP->fr_var)))) 1608 1644 abort (); … … 1699 1735 /* This is the offset from ??? to table_ptr+0. */ 1700 1736 to_addr = table_addr - S_GET_VALUE (lie->sub); 1701 #ifdef BFD_ASSEMBLER1702 to_addr -= symbol_get_frag (lie->sub)->fr_address;1703 #endif1704 1737 #ifdef TC_CHECK_ADJUSTED_BROKEN_DOT_WORD 1705 1738 TC_CHECK_ADJUSTED_BROKEN_DOT_WORD (to_addr, lie); … … 1718 1751 from_addr = table_addr; 1719 1752 to_addr = S_GET_VALUE (lie->add) + lie->addnum; 1720 #ifdef BFD_ASSEMBLER1721 to_addr += symbol_get_frag (lie->add)->fr_address;1722 #endif1723 1753 md_create_long_jump (table_ptr, from_addr, to_addr, lie->dispfrag, 1724 1754 lie->add); … … 1838 1868 1839 1869 #ifdef BFD_HEADERS 1840 bfd_seek (stdoutput, 0, 0);1841 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); 1842 1872 #else 1843 1873 … … 1863 1893 1864 1894 for (symp = symbol_rootP; symp; symp = symbol_next (symp)) 1865 resolve_symbol_value (symp , 1);1895 resolve_symbol_value (symp); 1866 1896 } 1867 1897 resolve_local_symbol_values (); … … 1877 1907 1878 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); 1879 1918 1880 1919 /* Set up symbol table, and write it out. */ … … 1905 1944 label name. */ 1906 1945 if (name2 != name && ! S_IS_DEFINED (symp)) 1907 as_bad (_("local label %sis not defined"), name2);1946 as_bad (_("local label `%s' is not defined"), name2); 1908 1947 } 1909 1948 … … 1911 1950 more symbols. They'll probably only be section symbols, 1912 1951 but they'll still need to have the values computed. */ 1913 resolve_symbol_value (symp , 1);1952 resolve_symbol_value (symp); 1914 1953 1915 1954 /* Skip symbols which were equated to undefined or common 1916 1955 symbols. */ 1917 if (symbol_equated_p (symp) 1918 && (! S_IS_DEFINED (symp) || S_IS_COMMON (symp))) 1956 if (symbol_equated_reloc_p (symp)) 1919 1957 { 1920 1958 symbol_remove (symp, &symbol_rootP, &symbol_lastP); … … 1948 1986 and symbols that the frob_symbol macros told us to punt, 1949 1987 but we keep such symbols if they are used in relocs. */ 1950 if ((! EMIT_SECTION_SYMBOLS 1951 && symbol_section_p (symp)) 1988 if (symp == abs_section_sym 1989 || (! EMIT_SECTION_SYMBOLS 1990 && symbol_section_p (symp)) 1952 1991 /* Note that S_IS_EXTERN and S_IS_LOCAL are not always 1953 1992 opposites. Sometimes the former checks flags and the 1954 1993 latter examines the name... */ 1955 1994 || (!S_IS_EXTERN (symp) 1956 && ( S_IS_LOCAL (symp) || punt)1995 && (punt || S_IS_LOCAL (symp)) 1957 1996 && ! symbol_used_in_reloc_p (symp))) 1958 1997 { … … 1968 2007 if (! symbol_resolved_p (symp)) 1969 2008 { 1970 as_bad (_("can't resolve value for symbol \"%s\""),2009 as_bad (_("can't resolve value for symbol `%s'"), 1971 2010 S_GET_NAME (symp)); 1972 2011 symbol_mark_resolved (symp); … … 2062 2101 know (sym_frag != NULL); 2063 2102 #endif 2064 know ( !(S_GET_SEGMENT (symbolP) == absolute_section)2103 know (S_GET_SEGMENT (symbolP) != absolute_section 2065 2104 || sym_frag == &zero_address_frag); 2066 target += S_GET_VALUE (symbolP) + sym_frag->fr_address;2105 target += S_GET_VALUE (symbolP); 2067 2106 2068 2107 /* If frag has yet to be reached on this pass, … … 2162 2201 addresses. */ 2163 2202 2164 void 2203 int 2165 2204 relax_segment (segment_frag_root, segment) 2166 2205 struct frag *segment_frag_root; … … 2169 2208 register struct frag *fragP; 2170 2209 register relax_addressT address; 2210 int ret; 2211 2171 2212 #if !defined (MANY_SEGMENTS) && !defined (BFD_ASSEMBLER) 2172 2213 know (segment == SEG_DATA || segment == SEG_TEXT || segment == SEG_BSS); … … 2201 2242 if (offset % fragP->fr_var != 0) 2202 2243 { 2203 as_bad (_("alignment padding (%lu bytes) not a multiple of %ld"), 2204 (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); 2205 2247 offset -= (offset % fragP->fr_var); 2206 2248 } … … 2216 2258 2217 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 2218 2266 address += md_estimate_size_before_relax (fragP, segment); 2219 2267 break; … … 2302 2350 continue; 2303 2351 2304 offset = (symbol_get_frag (lie->add)->fr_address 2305 + S_GET_VALUE (lie->add) 2352 offset = (S_GET_VALUE (lie->add) 2306 2353 + lie->addnum 2307 - (symbol_get_frag (lie->sub)->fr_address 2308 + S_GET_VALUE (lie->sub))); 2354 - S_GET_VALUE (lie->sub)); 2309 2355 if (offset <= -32768 || offset >= 32767) 2310 2356 { … … 2313 2359 char buf[50]; 2314 2360 sprint_value (buf, (addressT) lie->addnum); 2315 as_warn (_(".word %s-%s+%s didn't fit"), 2316 S_GET_NAME (lie->add), 2317 S_GET_NAME (lie->sub), 2318 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); 2319 2366 } 2320 2367 lie->added = 1; … … 2381 2428 || (symbolP->sy_frag == &zero_address_frag)); 2382 2429 #endif 2383 target += (S_GET_VALUE (symbolP) 2384 + symbol_get_frag (symbolP)->fr_address); 2385 } /* 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 } 2386 2437 2387 2438 know (fragP->fr_next); … … 2394 2445 .org backwards. */ 2395 2446 as_bad_where (fragP->fr_file, fragP->fr_line, 2396 _("attempt to .org backwards ignored"));2447 _("attempt to .org backwards")); 2397 2448 2398 2449 /* We've issued an error message. Change the … … 2411 2462 2412 2463 case rs_space: 2464 growth = 0; 2413 2465 if (symbolP) 2414 2466 { 2415 growth = S_GET_VALUE (symbolP); 2416 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 2417 2471 || S_IS_COMMON (symbolP) 2418 2472 || ! S_IS_DEFINED (symbolP)) 2419 as_bad_where (fragP->fr_file, fragP->fr_line,2420 _(".space specifies non-absolute value"));2421 fragP->fr_symbol = 0;2422 if (growth < 0)2423 2473 { 2424 as_warn (_(".space or .fill with negative value, ignored")); 2425 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; 2426 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); 2427 2488 } 2428 else2429 growth = 0;2430 2489 break; 2431 2490 … … 2447 2506 int size; 2448 2507 2449 value = resolve_symbol_value (fragP->fr_symbol , 0);2508 value = resolve_symbol_value (fragP->fr_symbol); 2450 2509 size = sizeof_leb128 (value, fragP->fr_subtype); 2451 2510 growth = size - fragP->fr_offset; … … 2476 2535 } /* do_relax */ 2477 2536 2478 /* We now have valid fr_address'es for each frag. */ 2479 2480 /* All fr_address's are correct, relative to their own segment. 2481 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; 2482 2545 } 2483 2546 2484 2547 #if defined (BFD_ASSEMBLER) || (!defined (BFD) && !defined (OBJ_VMS)) 2485 2486 #ifndef TC_RELOC_RTSYM_LOC_FIXUP2487 #define TC_RELOC_RTSYM_LOC_FIXUP(X) (1)2488 #endif2489 2548 2490 2549 /* fixup_segment() … … 2493 2552 handled now. (These consist of fixS where we have since discovered 2494 2553 the value of a symbol, or the address of the frag involved.) 2495 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. 2496 2555 2497 2556 Result is a count of how many relocation structs will be needed to … … 2500 2559 2501 2560 static long 2502 fixup_segment (fixP, this_segment _type)2503 registerfixS *fixP;2504 segT this_segment _type; /* N_TYPE bits for segment. */2561 fixup_segment (fixP, this_segment) 2562 fixS *fixP; 2563 segT this_segment; 2505 2564 { 2506 2565 long seg_reloc_count = 0; 2507 symbolS *add_symbolP;2508 symbolS *sub_symbolP;2509 2566 valueT add_number; 2510 int size;2511 char *place;2512 long where;2513 int pcrel, plt;2514 2567 fragS *fragP; 2515 2568 segT add_symbol_segment = absolute_section; 2516 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 2517 2579 /* If the linker is doing the relaxing, we must not do any fixups. 2518 2580 2519 Well, strictly speaking that's not true -- we could do any that are 2520 PC-relative and don't cross regions that could change size. And for the 2521 i960 (the only machine for which we've got a relaxing linker right now), 2522 we might be able to turn callx/callj into bal anyways in cases where we 2523 know the maximum displacement. */ 2524 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)) 2525 2586 { 2526 2587 for (; fixP; fixP = fixP->fx_next) 2527 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 } 2528 2603 TC_ADJUST_RELOC_COUNT (fixP, seg_reloc_count); 2529 2604 return seg_reloc_count; … … 2539 2614 fragP = fixP->fx_frag; 2540 2615 know (fragP); 2541 where = fixP->fx_where;2542 place = fragP->fr_literal + where;2543 size = fixP->fx_size;2544 add_symbolP = fixP->fx_addsy;2545 2616 #ifdef TC_VALIDATE_FIX 2546 TC_VALIDATE_FIX (fixP, this_segment_type, skip); 2547 #endif 2548 sub_symbolP = fixP->fx_subsy; 2617 TC_VALIDATE_FIX (fixP, this_segment, skip); 2618 #endif 2549 2619 add_number = fixP->fx_offset; 2550 pcrel = fixP->fx_pcrel; 2551 plt = fixP->fx_plt; 2552 2553 if (add_symbolP != NULL 2554 && symbol_mri_common_p (add_symbolP)) 2620 2621 if (fixP->fx_addsy != NULL 2622 && symbol_mri_common_p (fixP->fx_addsy)) 2555 2623 { 2556 know ( add_symbolP->sy_value.X_op == O_symbol);2557 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); 2558 2626 fixP->fx_offset = add_number; 2559 add_symbolP = fixP->fx_addsy =2560 symbol_get_value_expression (add_symbolP)->X_add_symbol;2627 fixP->fx_addsy 2628 = symbol_get_value_expression (fixP->fx_addsy)->X_add_symbol; 2561 2629 } 2562 2630 2563 if ( add_symbolP)2564 add_symbol_segment = S_GET_SEGMENT ( add_symbolP);2565 2566 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) 2567 2635 { 2568 resolve_symbol_value (sub_symbolP, 1); 2569 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)) 2570 2642 { 2571 if (add_symbolP != NULL) 2572 { 2573 add_number += S_GET_VALUE (add_symbolP); 2574 add_symbolP = NULL; 2575 fixP->fx_addsy = NULL; 2576 } 2577 2578 /* It's just -sym. */ 2579 if (S_GET_SEGMENT (sub_symbolP) == absolute_section) 2580 { 2581 add_number -= S_GET_VALUE (sub_symbolP); 2582 fixP->fx_subsy = NULL; 2583 } 2584 else if (pcrel 2585 && S_GET_SEGMENT (sub_symbolP) == this_segment_type) 2586 { 2587 /* Should try converting to a constant. */ 2588 goto bad_sub_reloc; 2589 } 2590 else 2591 bad_sub_reloc: 2592 as_bad_where (fixP->fx_file, fixP->fx_line, 2593 _("Negative of non-absolute symbol %s"), 2594 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; 2595 2658 } 2596 else if ( S_GET_SEGMENT (sub_symbolP) == add_symbol_segment2597 && SEG_NORMAL (add_symbol_segment))2659 else if (sub_symbol_segment == absolute_section 2660 && !TC_FORCE_RELOCATION_SUB_ABS (fixP)) 2598 2661 { 2599 /* Difference of 2 symbols from same segment. 2600 Can't make difference of 2 undefineds: 'value' means 2601 something different for N_UNDF. */ 2602 #ifdef TC_I960 2603 /* Makes no sense to use the difference of 2 arbitrary symbols 2604 as the target of a call instruction. */ 2605 if (fixP->fx_tcbit) 2606 as_bad_where (fixP->fx_file, fixP->fx_line, 2607 _("callj to difference of 2 symbols")); 2608 #endif /* TC_I960 */ 2609 add_number += S_GET_VALUE (add_symbolP) - 2610 S_GET_VALUE (sub_symbolP); 2611 2612 add_symbolP = NULL; 2613 pcrel = 0; /* No further pcrel processing. */ 2614 2615 /* Let the target machine make the final determination 2616 as to whether or not a relocation will be needed to 2617 handle this fixup. */ 2618 if (!TC_FORCE_RELOCATION_SECTION (fixP, this_segment_type)) 2619 { 2620 fixP->fx_pcrel = 0; 2621 fixP->fx_addsy = NULL; 2622 fixP->fx_subsy = NULL; 2623 } 2662 add_number -= S_GET_VALUE (fixP->fx_subsy); 2663 fixP->fx_offset = add_number; 2664 fixP->fx_subsy = NULL; 2624 2665 } 2625 else 2666 else if (sub_symbol_segment == this_segment 2667 && !TC_FORCE_RELOCATION_SUB_LOCAL (fixP)) 2626 2668 { 2627 /* Different segments in subtraction. */ 2628 know (!(S_IS_EXTERNAL (sub_symbolP) 2629 && (S_GET_SEGMENT (sub_symbolP) == absolute_section))); 2630 2631 if ((S_GET_SEGMENT (sub_symbolP) == absolute_section)) 2632 add_number -= S_GET_VALUE (sub_symbolP); 2633 2634 #ifdef DIFF_EXPR_OK 2635 else if (S_GET_SEGMENT (sub_symbolP) == this_segment_type 2636 #if 0 2637 /* Do this even if it's already described as 2638 pc-relative. For example, on the m68k, an 2639 operand of "pc@(foo-.-2)" should address 2640 "foo" in a pc-relative mode. */ 2641 && pcrel 2642 #endif 2643 ) 2644 { 2645 /* Make it pc-relative. */ 2646 add_number += (MD_PCREL_FROM_SECTION (fixP, this_segment_type) 2647 - S_GET_VALUE (sub_symbolP)); 2648 pcrel = 1; 2649 fixP->fx_pcrel = 1; 2650 sub_symbolP = 0; 2651 fixP->fx_subsy = 0; 2652 } 2653 #endif 2654 #ifdef UNDEFINED_DIFFERENCE_OK 2655 /* The PA needs this for PIC code generation. We basically 2656 don't want to do anything if we have the difference of two 2657 symbols at this point. */ 2658 else if (1) 2659 { 2660 /* Leave it alone. */ 2661 } 2662 #endif 2663 #ifdef BFD_ASSEMBLER 2664 else if (fixP->fx_r_type == BFD_RELOC_GPREL32 2665 || fixP->fx_r_type == BFD_RELOC_GPREL16) 2666 { 2667 /* Leave it alone. */ 2668 } 2669 #endif 2670 else 2671 { 2672 char buf[50]; 2673 sprint_value (buf, fragP->fr_address + where); 2674 as_bad_where (fixP->fx_file, fixP->fx_line, 2675 _("Subtraction of two symbols in different sections \"%s\" {%s section} - \"%s\" {%s section} at file address %s."), 2676 S_GET_NAME (add_symbolP), 2677 segment_name (S_GET_SEGMENT (add_symbolP)), 2678 S_GET_NAME (sub_symbolP), 2679 segment_name (S_GET_SEGMENT (sub_symbolP)), 2680 buf); 2681 } 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)); 2682 2697 } 2683 2698 } 2684 2699 2685 if ( add_symbolP)2700 if (fixP->fx_addsy) 2686 2701 { 2687 if (add_symbol_segment == this_segment _type && pcrel && !plt2688 && TC_RELOC_RTSYM_LOC_FIXUP(fixP))2702 if (add_symbol_segment == this_segment 2703 && !TC_FORCE_RELOCATION_LOCAL (fixP)) 2689 2704 { 2690 2705 /* This fixup was made when the symbol's segment was 2691 2706 SEG_UNKNOWN, but it is now in the local segment. 2692 2707 So we know how to do the address without relocation. */ 2693 #ifdef TC_I960 2694 /* reloc_callj() may replace a 'call' with a 'calls' or a 2695 'bal', in which cases it modifies *fixP as appropriate. 2696 In the case of a 'calls', no further work is required, 2697 and *fixP has been set up to make the rest of the code 2698 below a no-op. */ 2699 reloc_callj (fixP); 2700 #endif /* TC_I960 */ 2701 2702 add_number += S_GET_VALUE (add_symbolP); 2703 add_number -= MD_PCREL_FROM_SECTION (fixP, this_segment_type); 2704 /* Lie. Don't want further pcrel processing. */ 2705 pcrel = 0; 2706 2707 /* Let the target machine make the final determination 2708 as to whether or not a relocation will be needed to 2709 handle this fixup. */ 2710 if (!TC_FORCE_RELOCATION (fixP)) 2711 { 2712 fixP->fx_pcrel = 0; 2713 fixP->fx_addsy = NULL; 2714 } 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; 2715 2714 } 2716 else 2715 else if (add_symbol_segment == absolute_section 2716 && !TC_FORCE_RELOCATION_ABS (fixP)) 2717 2717 { 2718 if (add_symbol_segment == absolute_section 2719 && ! pcrel) 2720 { 2721 #ifdef TC_I960 2722 /* See comment about reloc_callj() above. */ 2723 reloc_callj (fixP); 2724 #endif /* TC_I960 */ 2725 add_number += S_GET_VALUE (add_symbolP); 2726 2727 /* Let the target machine make the final determination 2728 as to whether or not a relocation will be needed to 2729 handle this fixup. */ 2730 2731 if (!TC_FORCE_RELOCATION (fixP)) 2732 { 2733 fixP->fx_addsy = NULL; 2734 add_symbolP = NULL; 2735 } 2736 } 2737 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 2738 2723 #ifdef BFD_ASSEMBLER 2739 || bfd_is_com_section (add_symbol_segment) 2740 #endif 2741 ) 2742 { 2743 #ifdef TC_I960 2744 if ((int) fixP->fx_bit_fixP == 13) 2745 { 2746 /* This is a COBR instruction. They have only a 2747 13-bit displacement and are only to be used 2748 for local branches: flag as error, don't generate 2749 relocation. */ 2750 as_bad_where (fixP->fx_file, fixP->fx_line, 2751 _("can't use COBR format with external label")); 2752 fixP->fx_addsy = NULL; 2753 fixP->fx_done = 1; 2754 continue; 2755 } /* COBR. */ 2756 #endif /* TC_I960 */ 2757 2758 #ifdef OBJ_COFF 2759 #ifdef TE_I386AIX 2760 if (S_IS_COMMON (add_symbolP)) 2761 add_number += S_GET_VALUE (add_symbolP); 2762 #endif /* TE_I386AIX */ 2763 #endif /* OBJ_COFF */ 2764 ++seg_reloc_count; 2765 } 2766 else 2767 { 2768 seg_reloc_count++; 2769 if (TC_FIX_ADJUSTABLE (fixP)) 2770 add_number += S_GET_VALUE (add_symbolP); 2771 } 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; 2772 2740 } 2773 2741 } 2774 2742 2775 if (pcrel) 2776 { 2777 add_number -= MD_PCREL_FROM_SECTION (fixP, this_segment_type); 2778 if (add_symbolP == 0) 2779 { 2780 #ifndef BFD_ASSEMBLER 2781 fixP->fx_addsy = &abs_symbol; 2782 #else 2783 fixP->fx_addsy = section_symbol (absolute_section); 2784 #endif 2785 symbol_mark_used_in_reloc (fixP->fx_addsy); 2786 ++seg_reloc_count; 2787 } 2788 } 2743 if (!fixP->fx_done) 2744 md_apply_fix3 (fixP, &add_number, this_segment); 2789 2745 2790 2746 if (!fixP->fx_done) 2791 2747 { 2792 #ifdef MD_APPLY_FIX3 2793 md_apply_fix3 (fixP, &add_number, this_segment_type); 2794 #else 2795 #ifdef BFD_ASSEMBLER 2796 md_apply_fix (fixP, &add_number); 2797 #else 2798 md_apply_fix (fixP, add_number); 2799 #endif 2800 #endif 2801 2802 #ifndef TC_HANDLES_FX_DONE 2803 /* If the tc-* files haven't been converted, assume it's handling 2804 it the old way, where a null fx_addsy means that the fix has 2805 been applied completely, and no further work is needed. */ 2806 if (fixP->fx_addsy == 0 && fixP->fx_pcrel == 0) 2807 fixP->fx_done = 1; 2808 #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); 2809 2754 } 2810 2755 2811 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) 2812 2757 { 2813 if ( (size_t)size < sizeof (valueT))2758 if (fixP->fx_size < sizeof (valueT)) 2814 2759 { 2815 2760 valueT mask; … … 2817 2762 mask = 0; 2818 2763 mask--; /* Set all bits to one. */ 2819 mask <<= size * 8 - (fixP->fx_signed ? 1 : 0);2764 mask <<= fixP->fx_size * 8 - (fixP->fx_signed ? 1 : 0); 2820 2765 if ((add_number & mask) != 0 && (add_number & mask) != mask) 2821 2766 { 2822 2767 char buf[50], buf2[50]; 2823 sprint_value (buf, fragP->fr_address + where);2768 sprint_value (buf, fragP->fr_address + fixP->fx_where); 2824 2769 if (add_number > 1000) 2825 2770 sprint_value (buf2, add_number); … … 2827 2772 sprintf (buf2, "%ld", (long) add_number); 2828 2773 as_bad_where (fixP->fx_file, fixP->fx_line, 2829 _(" Value of %s too large for field of %d bytes at %s"),2830 buf2, size, buf);2774 _("value of %s too large for field of %d bytes at %s"), 2775 buf2, fixP->fx_size, buf); 2831 2776 } /* Generic error checking. */ 2832 2777 } … … 2836 2781 catch over-large switches generated by gcc on the 68k. */ 2837 2782 if (!flag_signed_overflow_ok 2838 && size == 22783 && fixP->fx_size == 2 2839 2784 && add_number > 0x7fff) 2840 2785 as_bad_where (fixP->fx_file, fixP->fx_line, 2841 _(" 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"), 2842 2787 (long) add_number, 2843 ( unsigned long) (fragP->fr_address +where));2788 (long) (fragP->fr_address + fixP->fx_where)); 2844 2789 #endif 2845 2790 } /* Not a bit fix. */ … … 2867 2812 int n; 2868 2813 { 2869 if ( (size_t) n > sizeof (val) ||n <= 0)2814 if (n <= 0) 2870 2815 abort (); 2871 2816 while (n--) … … 2882 2827 int n; 2883 2828 { 2884 if ( (size_t) n > sizeof (val) ||n <= 0)2829 if (n <= 0) 2885 2830 abort (); 2886 2831 while (n--) -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.