Ignore:
Timestamp:
Aug 16, 2003, 11:33:53 PM (22 years ago)
Author:
bird
Message:

Joined the port of 2.11.2 with 2.14.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/binutils/gas/write.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r617 r618  
    11/* write.c - emit .o file
    22   Copyright 1986, 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
    3    1998, 1999, 2000, 2001
     3   1998, 1999, 2000, 2001, 2002, 2003
    44   Free Software Foundation, Inc.
    55
     
    2929#include "dwarf2dbg.h"
    3030
    31 /* This looks like a good idea.  Let's try turning it on always, for now.  */
    32 #undef  BFD_FAST_SECTION_FILL
    33 #define BFD_FAST_SECTION_FILL
    34 
    3531#ifndef TC_ADJUST_RELOC_COUNT
    36 #define TC_ADJUST_RELOC_COUNT(FIXP,COUNT)
     32#define TC_ADJUST_RELOC_COUNT(FIX, COUNT)
    3733#endif
    3834
    3935#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
    4582#endif
    4683
     
    4986#endif
    5087
    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
    5394#endif
    5495
    5596#ifndef MD_PCREL_FROM_SECTION
    56 #define MD_PCREL_FROM_SECTION(FIXP, SEC) md_pcrel_from(FIXP)
     97#define MD_PCREL_FROM_SECTION(FIX, SEC) md_pcrel_from (FIX)
    5798#endif
    5899
    59100#ifndef WORKING_DOT_WORD
    60 extern CONST int md_short_jump_size;
    61 extern CONST int md_long_jump_size;
    62 #endif
     101extern const int md_short_jump_size;
     102extern const int md_long_jump_size;
     103#endif
     104
     105/* Used to control final evaluation of expressions.  */
     106int finalize_syms = 0;
    63107
    64108int symbol_table_frozen;
     109
     110symbolS *abs_section_sym;
     111
     112/* Remember the value of dot when parsing expressions.  */
     113addressT dot_value;
     114
    65115void print_fixup PARAMS ((fixS *));
    66116
     
    103153
    104154#ifdef BFD_ASSEMBLER
     155#define RELOC_ENUM enum bfd_reloc_code_real
     156#else
     157#define RELOC_ENUM int
     158#endif
     159
    105160static fixS *fix_new_internal PARAMS ((fragS *, int where, int size,
    106161                                       symbolS *add, symbolS *sub,
    107162                                       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));
    115164#if defined (BFD_ASSEMBLER) || (!defined (BFD) && !defined (OBJ_VMS))
    116 static long fixup_segment PARAMS ((fixS * fixP, segT this_segment_type));
     165static long fixup_segment PARAMS ((fixS *, segT));
    117166#endif
    118167static relax_addressT relax_align PARAMS ((relax_addressT addr, int align));
     
    123172static void chain_frchains_together PARAMS ((bfd *, segT, PTR));
    124173static 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));
    127174static void adjust_reloc_syms PARAMS ((bfd *, asection *, PTR));
     175static void fix_segment PARAMS ((bfd *, asection *, PTR));
    128176static void write_relocs PARAMS ((bfd *, asection *, PTR));
    129177static void write_contents PARAMS ((bfd *, asection *, PTR));
     
    137185static void remove_subsegs PARAMS ((frchainS *, int, fragS **, fragS **));
    138186static void relax_and_size_all_segments PARAMS ((void));
    139 #endif
    140 #if defined (BFD_ASSEMBLER) && defined (OBJ_COFF) && defined (TE_GO32)
    141 static void set_segment_vma PARAMS ((bfd *, asection *, PTR));
    142187#endif
    143188
     
    154199     offsetT offset;            /* X_add_number.  */
    155200     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.  */
    161202{
    162203  fixS *fixP;
     
    178219  fixP->fx_subsy = sub_symbol;
    179220  fixP->fx_offset = offset;
     221  fixP->fx_dot_value = dot_value;
    180222  fixP->fx_pcrel = pcrel;
    181223  fixP->fx_plt = 0;
     
    249291     offsetT offset;            /* X_add_number.  */
    250292     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.  */
    256294{
    257295  return fix_new_internal (frag, where, size, add_symbol,
     
    270308     expressionS *exp;          /* Expression.  */
    271309     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.  */
    277311{
    278312  symbolS *add = NULL;
     
    339373
    340374  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.  */
     378int
     379generic_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);
    341388}
    342389
     
    523570                        _("attempt to .org/.space backwards? (%ld)"),
    524571                        (long) fragP->fr_offset);
     572          fragP->fr_offset = 0;
    525573        }
    526574      fragP->fr_type = rs_fill;
     
    599647
    600648#ifdef BFD_ASSEMBLER
     649static void relax_seg PARAMS ((bfd *, asection *, PTR));
    601650static void
    602 relax_seg (abfd, sec, do_code)
    603      bfd *abfd;
     651relax_seg (abfd, sec, xxx)
     652     bfd *abfd ATTRIBUTE_UNUSED;
    604653     asection *sec;
    605      PTR do_code;
    606 {
    607   flagword flags = bfd_get_section_flags (abfd, sec);
     654     PTR xxx;
     655{
    608656  segment_info_type *seginfo = seg_info (sec);
    609657
    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
     666static void size_seg PARAMS ((bfd *, asection *, PTR));
    615667static void
    616668size_seg (abfd, sec, xxx)
     
    653705    flags &= ~SEC_RELOC;
    654706  x = bfd_set_section_flags (abfd, sec, flags);
    655   assert (x == true);
     707  assert (x);
    656708
    657709  newsize = md_section_align (sec, size);
    658710  x = bfd_set_section_size (abfd, sec, newsize);
    659   assert (x == true);
     711  assert (x);
    660712
    661713  /* If the size had to be rounded up, add some padding in the last
     
    669721        fragp = fragp->fr_next;
    670722      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 ();
    672731    }
    673732
     
    719778#endif
    720779
     780/* This pass over fixups decides whether symbols can be replaced with
     781   section symbols.  */
     782
    721783static void
    722784adjust_reloc_syms (abfd, sec, xxx)
     
    753815           symbols, though, since they are not in the regular symbol
    754816           table.  */
    755         if (sym != NULL)
    756           resolve_symbol_value (sym, 1);
     817        resolve_symbol_value (sym);
    757818
    758819        if (fixp->fx_subsy != NULL)
    759           resolve_symbol_value (fixp->fx_subsy, 1);
     820          resolve_symbol_value (fixp->fx_subsy);
    760821
    761822        /* If this symbol is equated to an undefined symbol, convert
    762823           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))
    765825          {
    766826            fixp->fx_offset += symbol_get_value_expression (sym)->X_add_number;
     
    769829          }
    770830
    771         if (sym != NULL && symbol_mri_common_p (sym))
     831        if (symbol_mri_common_p (sym))
    772832          {
    773833            /* These symbols are handled specially in fixup_segment.  */
    774             goto done;
     834            continue;
    775835          }
    776836
     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
    777855        symsec = S_GET_SEGMENT (sym);
    778 
    779856        if (symsec == NULL)
    780857          abort ();
     
    782859        if (bfd_is_abs_section (symsec))
    783860          {
    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;
    814864          }
    815865
     
    820870        if (symsec != sec && ! S_IS_LOCAL (sym))
    821871          {
    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;
    848880          }
    849881
    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
    900893           than using symsec, because S_GET_VALUE may wind up changing
    901894           the section when it calls resolve_symbol_value.  */
    902895        fixp->fx_offset += S_GET_VALUE (sym);
    903896        fixp->fx_addsy = section_symbol (S_GET_SEGMENT (sym));
    904         symbol_mark_used_in_reloc (fixp->fx_addsy);
    905897#ifdef DEBUG5
    906898        fprintf (stderr, "\nadjusted fixup:\n");
    907899        print_fixup (fixp);
    908900#endif
    909 
    910       done:
    911         ;
    912901      }
    913 #if 1 /* def RELOC_REQUIRES_SYMBOL  */
    914     else
    915       {
    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 up
    919            a local symbol in the absolute section.  */
    920 
    921         fixp->fx_addsy = section_symbol (absolute_section);
    922 #if 0
    923         fixp->fx_addsy->sy_used_in_reloc = 1;
    924 #endif
    925       }
    926 #endif
    927902
    928903  dump_section_relocs (abfd, sec, stderr);
     904}
     905
     906static void
     907fix_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);
    929915}
    930916
     
    947933    return;
    948934
    949   fixup_segment (seginfo->fix_root, sec);
    950 
    951935  n = 0;
    952936  for (fixp = seginfo->fix_root; fixp; fixp = fixp->fx_next)
     
    972956
    973957      /* If this is an undefined symbol which was equated to another
    974          symbol, then use generate the reloc against the latter symbol
     958         symbol, then generate the reloc against the latter symbol
    975959         rather than the former.  */
    976960      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))
    979962        {
    980963          symbolS *n;
     
    1013996          break;
    1014997        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"));
    10161000          break;
    10171001        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"));
    10191004          break;
    10201005        default:
     
    10331018    {
    10341019      arelent **reloc;
    1035       char *data;
    10361020      bfd_reloc_status_type s;
    10371021      symbolS *sym;
     
    10481032         rather than the former.  */
    10491033      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        }
    10531046      fixp->fx_addsy = sym;
    10541047
     
    10601053          assert (i <= n);
    10611054        }
    1062       data = fixp->fx_frag->fr_literal + fixp->fx_where;
    10631055      if (fixp->fx_where + fixp->fx_size
    10641056          > fixp->fx_frag->fr_fix + fixp->fx_frag->fr_offset)
     
    10791071                            _("relocation overflow"));
    10801072              break;
     1073            case bfd_reloc_outofrange:
     1074              as_bad_where (fixp->fx_file, fixp->fx_line,
     1075                            _("relocation out of range"));
     1076              break;
    10811077            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);
    10841080            }
    10851081        }
     
    11641160                                        f->fr_literal, (file_ptr) offset,
    11651161                                        (bfd_size_type) f->fr_fix);
    1166           if (x == false)
     1162          if (!x)
    11671163            {
    11681164              bfd_perror (stdoutput->filename);
     
    11881184                                                (file_ptr) offset,
    11891185                                                (bfd_size_type) fill_size);
    1190                   if (x == false)
     1186                  if (!x)
    11911187                    {
    11921188                      bfd_perror (stdoutput->filename);
     
    12221218                    (stdoutput, sec, buf, (file_ptr) offset,
    12231219                     (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"));
    12261222                  offset += n_per_buf * fill_size;
    12271223                }
     
    13561352  asymbol **asympp;
    13571353  symbolS *symp;
    1358   boolean result;
    1359   extern PTR bfd_alloc PARAMS ((bfd *, size_t));
     1354  bfd_boolean result;
     1355  extern PTR bfd_alloc PARAMS ((bfd *, bfd_size_type));
    13601356
    13611357  /* Count symbols.  We can't rely on a count made by the loop in
     
    13691365    {
    13701366      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);
    13741370      symp = symbol_rootP;
    13751371      for (i = 0; i < nsyms; i++, symp = symbol_next (symp))
     
    13821378    asympp = 0;
    13831379  result = bfd_set_symtab (stdoutput, asympp, nsyms);
    1384   assert (result == true);
     1380  assert (result);
    13851381  symbol_table_frozen = 1;
    13861382}
    13871383#endif
    1388 
    1389 #if defined (BFD_ASSEMBLER) && defined (OBJ_COFF) && defined (TE_GO32)
    1390 static void
    1391 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  */
    14021384
    14031385/* Finish the subsegments.  After every sub-segment, we fake an
     
    14081390
    14091391#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
    14101400#ifdef BFD_ASSEMBLER
    1411 #define SUB_SEGMENT_ALIGN(SEG) (0)
     1401#define SUB_SEGMENT_ALIGN(SEG, FRCHAIN) 0
    14121402#else
    1413 #define SUB_SEGMENT_ALIGN(SEG) (2)
     1403#define SUB_SEGMENT_ALIGN(SEG, FRCHAIN) 2
     1404#endif
    14141405#endif
    14151406#endif
     
    14221413  for (frchainP = frchain_root; frchainP; frchainP = frchainP->frch_next)
    14231414    {
    1424       int alignment;
     1415      int alignment = 0;
    14251416
    14261417      subseg_set (frchainP->frch_seg, frchainP->frch_subseg);
     
    14291420         any alignment is meaningless, and, moreover, will look weird
    14301421         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        }
    14381442
    14391443      if (subseg_text_p (now_seg))
     
    14721476      {
    14731477        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"),
    14751479                   n_errs, n_errs == 1 ? "" : "s",
    14761480                   n_warns, n_warns == 1 ? "" : "s");
     
    14791483      {
    14801484        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"),
    14821486                    n_errs, n_errs == 1 ? "" : "s",
    14831487                    n_warns, n_warns == 1 ? "" : "s");
     
    14981502  /* Remove the sections created by gas for its own purposes.  */
    14991503  {
    1500     asection **seclist, *sec;
     1504    asection **seclist;
    15011505    int i;
    15021506
    15031507    seclist = &stdoutput->sections;
    1504     while (seclist && *seclist)
     1508    while (*seclist)
    15051509      {
    1506         sec = *seclist;
    1507         while (sec == reg_section || sec == expr_section)
     1510        if (*seclist == reg_section || *seclist == expr_section)
    15081511          {
    1509             sec = sec->next;
    1510             *seclist = sec;
     1512            bfd_section_list_remove (stdoutput, seclist);
    15111513            stdoutput->section_count--;
    1512             if (!sec)
    1513               break;
    15141514          }
    1515         if (*seclist)
     1515        else
    15161516          seclist = &(*seclist)->next;
    15171517      }
     
    15381538
    15391539#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
    15421579  bfd_map_over_sections (stdoutput, size_seg, (char *) 0);
    15431580#else
     
    15451582#endif /* BFD_ASSEMBLER  */
    15461583
    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;
    15531589#endif
    15541590
     
    16041640            || fragP->fr_next == data_frag_root
    16051641#endif
    1606             || ((fragP->fr_next->fr_address - fragP->fr_address)
     1642            || ((offsetT) (fragP->fr_next->fr_address - fragP->fr_address)
    16071643                == (fragP->fr_fix + fragP->fr_offset * fragP->fr_var))))
    16081644        abort ();
     
    16991735            /* This is the offset from ??? to table_ptr+0.  */
    17001736            to_addr = table_addr - S_GET_VALUE (lie->sub);
    1701 #ifdef BFD_ASSEMBLER
    1702             to_addr -= symbol_get_frag (lie->sub)->fr_address;
    1703 #endif
    17041737#ifdef TC_CHECK_ADJUSTED_BROKEN_DOT_WORD
    17051738            TC_CHECK_ADJUSTED_BROKEN_DOT_WORD (to_addr, lie);
     
    17181751            from_addr = table_addr;
    17191752            to_addr = S_GET_VALUE (lie->add) + lie->addnum;
    1720 #ifdef BFD_ASSEMBLER
    1721             to_addr += symbol_get_frag (lie->add)->fr_address;
    1722 #endif
    17231753            md_create_long_jump (table_ptr, from_addr, to_addr, lie->dispfrag,
    17241754                                 lie->add);
     
    18381868
    18391869#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);
    18421872#else
    18431873
     
    18631893
    18641894      for (symp = symbol_rootP; symp; symp = symbol_next (symp))
    1865         resolve_symbol_value (symp, 1);
     1895        resolve_symbol_value (symp);
    18661896    }
    18671897  resolve_local_symbol_values ();
     
    18771907
    18781908  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);
    18791918
    18801919  /* Set up symbol table, and write it out.  */
     
    19051944                 label name.  */
    19061945              if (name2 != name && ! S_IS_DEFINED (symp))
    1907                 as_bad (_("local label %s is not defined"), name2);
     1946                as_bad (_("local label `%s' is not defined"), name2);
    19081947            }
    19091948
     
    19111950             more symbols.  They'll probably only be section symbols,
    19121951             but they'll still need to have the values computed.  */
    1913           resolve_symbol_value (symp, 1);
     1952          resolve_symbol_value (symp);
    19141953
    19151954          /* Skip symbols which were equated to undefined or common
    19161955             symbols.  */
    1917           if (symbol_equated_p (symp)
    1918               && (! S_IS_DEFINED (symp) || S_IS_COMMON (symp)))
     1956          if (symbol_equated_reloc_p (symp))
    19191957            {
    19201958              symbol_remove (symp, &symbol_rootP, &symbol_lastP);
     
    19481986             and symbols that the frob_symbol macros told us to punt,
    19491987             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))
    19521991              /* Note that S_IS_EXTERN and S_IS_LOCAL are not always
    19531992                 opposites.  Sometimes the former checks flags and the
    19541993                 latter examines the name...  */
    19551994              || (!S_IS_EXTERN (symp)
    1956                   && (S_IS_LOCAL (symp) || punt)
     1995                  && (punt || S_IS_LOCAL (symp))
    19571996                  && ! symbol_used_in_reloc_p (symp)))
    19581997            {
     
    19682007          if (! symbol_resolved_p (symp))
    19692008            {
    1970               as_bad (_("can't resolve value for symbol \"%s\""),
     2009              as_bad (_("can't resolve value for symbol `%s'"),
    19712010                      S_GET_NAME (symp));
    19722011              symbol_mark_resolved (symp);
     
    20622101      know (sym_frag != NULL);
    20632102#endif
    2064       know (!(S_GET_SEGMENT (symbolP) == absolute_section)
     2103      know (S_GET_SEGMENT (symbolP) != absolute_section
    20652104            || sym_frag == &zero_address_frag);
    2066       target += S_GET_VALUE (symbolP) + sym_frag->fr_address;
     2105      target += S_GET_VALUE (symbolP);
    20672106
    20682107      /* If frag has yet to be reached on this pass,
     
    21622201   addresses.  */
    21632202
    2164 void
     2203int
    21652204relax_segment (segment_frag_root, segment)
    21662205     struct frag *segment_frag_root;
     
    21692208  register struct frag *fragP;
    21702209  register relax_addressT address;
     2210  int ret;
     2211
    21712212#if !defined (MANY_SEGMENTS) && !defined (BFD_ASSEMBLER)
    21722213  know (segment == SEG_DATA || segment == SEG_TEXT || segment == SEG_BSS);
     
    22012242            if (offset % fragP->fr_var != 0)
    22022243              {
    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);
    22052247                offset -= (offset % fragP->fr_var);
    22062248              }
     
    22162258
    22172259        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
    22182266          address += md_estimate_size_before_relax (fragP, segment);
    22192267          break;
     
    23022350                        continue;
    23032351
    2304                       offset = (symbol_get_frag (lie->add)->fr_address
    2305                                 + S_GET_VALUE (lie->add)
     2352                      offset = (S_GET_VALUE (lie->add)
    23062353                                + lie->addnum
    2307                                 - (symbol_get_frag (lie->sub)->fr_address
    2308                                    + S_GET_VALUE (lie->sub)));
     2354                                - S_GET_VALUE (lie->sub));
    23092355                      if (offset <= -32768 || offset >= 32767)
    23102356                        {
     
    23132359                              char buf[50];
    23142360                              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);
    23192366                            }
    23202367                          lie->added = 1;
     
    23812428                            || (symbolP->sy_frag == &zero_address_frag));
    23822429#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                    }
    23862437
    23872438                  know (fragP->fr_next);
     
    23942445                         .org backwards.  */
    23952446                      as_bad_where (fragP->fr_file, fragP->fr_line,
    2396                                     _("attempt to .org backwards ignored"));
     2447                                    _("attempt to .org backwards"));
    23972448
    23982449                      /* We've issued an error message.  Change the
     
    24112462
    24122463              case rs_space:
     2464                growth = 0;
    24132465                if (symbolP)
    24142466                  {
    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
    24172471                        || S_IS_COMMON (symbolP)
    24182472                        || ! 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)
    24232473                      {
    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;
    24262478                      }
     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);
    24272488                  }
    2428                 else
    2429                   growth = 0;
    24302489                break;
    24312490
     
    24472506                  int size;
    24482507
    2449                   value = resolve_symbol_value (fragP->fr_symbol, 0);
     2508                  value = resolve_symbol_value (fragP->fr_symbol);
    24502509                  size = sizeof_leb128 (value, fragP->fr_subtype);
    24512510                  growth = size - fragP->fr_offset;
     
    24762535  }                             /* do_relax  */
    24772536
    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;
    24822545}
    24832546
    24842547#if defined (BFD_ASSEMBLER) || (!defined (BFD) && !defined (OBJ_VMS))
    2485 
    2486 #ifndef TC_RELOC_RTSYM_LOC_FIXUP
    2487 #define TC_RELOC_RTSYM_LOC_FIXUP(X) (1)
    2488 #endif
    24892548
    24902549/* fixup_segment()
     
    24932552   handled now.  (These consist of fixS where we have since discovered
    24942553   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.
    24962555
    24972556   Result is a count of how many relocation structs will be needed to
     
    25002559
    25012560static long
    2502 fixup_segment (fixP, this_segment_type)
    2503      register fixS *fixP;
    2504      segT this_segment_type;    /* N_TYPE bits for segment.  */
     2561fixup_segment (fixP, this_segment)
     2562     fixS *fixP;
     2563     segT this_segment;
    25052564{
    25062565  long seg_reloc_count = 0;
    2507   symbolS *add_symbolP;
    2508   symbolS *sub_symbolP;
    25092566  valueT add_number;
    2510   int size;
    2511   char *place;
    2512   long where;
    2513   int pcrel, plt;
    25142567  fragS *fragP;
    25152568  segT add_symbol_segment = absolute_section;
    25162569
     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
    25172579  /* If the linker is doing the relaxing, we must not do any fixups.
    25182580
    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))
    25252586    {
    25262587      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          }
    25282603      TC_ADJUST_RELOC_COUNT (fixP, seg_reloc_count);
    25292604      return seg_reloc_count;
     
    25392614      fragP = fixP->fx_frag;
    25402615      know (fragP);
    2541       where = fixP->fx_where;
    2542       place = fragP->fr_literal + where;
    2543       size = fixP->fx_size;
    2544       add_symbolP = fixP->fx_addsy;
    25452616#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
    25492619      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))
    25552623        {
    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);
    25582626          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;
    25612629        }
    25622630
    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)
    25672635        {
    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))
    25702642            {
    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;
    25952658            }
    2596           else if (S_GET_SEGMENT (sub_symbolP) == add_symbol_segment
    2597                    && SEG_NORMAL (add_symbol_segment))
     2659          else if (sub_symbol_segment == absolute_section
     2660                   && !TC_FORCE_RELOCATION_SUB_ABS (fixP))
    25982661            {
    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;
    26242665            }
    2625           else
     2666          else if (sub_symbol_segment == this_segment
     2667                   && !TC_FORCE_RELOCATION_SUB_LOCAL (fixP))
    26262668            {
    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));
    26822697            }
    26832698        }
    26842699
    2685       if (add_symbolP)
     2700      if (fixP->fx_addsy)
    26862701        {
    2687           if (add_symbol_segment == this_segment_type && pcrel && !plt
    2688               && TC_RELOC_RTSYM_LOC_FIXUP (fixP))
     2702          if (add_symbol_segment == this_segment
     2703              && !TC_FORCE_RELOCATION_LOCAL (fixP))
    26892704            {
    26902705              /* This fixup was made when the symbol's segment was
    26912706                 SEG_UNKNOWN, but it is now in the local segment.
    26922707                 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;
    27152714            }
    2716           else
     2715          else if (add_symbol_segment == absolute_section
     2716                   && !TC_FORCE_RELOCATION_ABS (fixP))
    27172717            {
    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
    27382723#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;
    27722740            }
    27732741        }
    27742742
    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);
    27892745
    27902746      if (!fixP->fx_done)
    27912747        {
    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);
    28092754        }
    28102755
    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)
    28122757        {
    2813           if ((size_t) size < sizeof (valueT))
     2758          if (fixP->fx_size < sizeof (valueT))
    28142759            {
    28152760              valueT mask;
     
    28172762              mask = 0;
    28182763              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);
    28202765              if ((add_number & mask) != 0 && (add_number & mask) != mask)
    28212766                {
    28222767                  char buf[50], buf2[50];
    2823                   sprint_value (buf, fragP->fr_address + where);
     2768                  sprint_value (buf, fragP->fr_address + fixP->fx_where);
    28242769                  if (add_number > 1000)
    28252770                    sprint_value (buf2, add_number);
     
    28272772                    sprintf (buf2, "%ld", (long) add_number);
    28282773                  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);
    28312776                } /* Generic error checking.  */
    28322777            }
     
    28362781             catch over-large switches generated by gcc on the 68k.  */
    28372782          if (!flag_signed_overflow_ok
    2838               && size == 2
     2783              && fixP->fx_size == 2
    28392784              && add_number > 0x7fff)
    28402785            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"),
    28422787                          (long) add_number,
    2843                           (unsigned long) (fragP->fr_address + where));
     2788                          (long) (fragP->fr_address + fixP->fx_where));
    28442789#endif
    28452790        }                       /* Not a bit fix.  */
     
    28672812     int n;
    28682813{
    2869   if ((size_t) n > sizeof (val) || n <= 0)
     2814  if (n <= 0)
    28702815    abort ();
    28712816  while (n--)
     
    28822827     int n;
    28832828{
    2884   if ((size_t) n > sizeof (val) || n <= 0)
     2829  if (n <= 0)
    28852830    abort ();
    28862831  while (n--)
Note: See TracChangeset for help on using the changeset viewer.