Ignore:
Timestamp:
Aug 16, 2003, 6:59:22 PM (22 years ago)
Author:
bird
Message:

binutils v2.14 - offical sources.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GNU/src/binutils/gas/write.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    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         /* We can never adjust a reloc against a weak symbol.  If we
    860            did, and the weak symbol was overridden by a real symbol
    861            somewhere else, then our relocation would be pointing at
    862            the wrong area of memory.  */
    863         if (S_IS_WEAK (sym))
    864           {
    865             symbol_mark_used_in_reloc (fixp->fx_addsy);
    866             goto done;
    867           }
    868 #endif
    869 
    870         /* Is there some other reason we can't adjust this one?  (E.g.,
    871            call/bal links in i960-bout symbols.)  */
    872 #ifdef obj_fix_adjustable
    873         if (! obj_fix_adjustable (fixp))
    874           {
    875             symbol_mark_used_in_reloc (fixp->fx_addsy);
    876             goto done;
    877           }
    878 #endif
    879 
    880         /* Is there some other (target cpu dependent) reason we can't adjust
    881            this one?  (E.g. relocations involving function addresses on
    882            the PA.  */
    883 #ifdef tc_fix_adjustable
    884         if (! tc_fix_adjustable (fixp))
    885           {
    886             symbol_mark_used_in_reloc (fixp->fx_addsy);
    887             goto done;
    888           }
    889 #endif
    890 
    891         /* If the section symbol isn't going to be output, the relocs
    892            at least should still work.  If not, figure out what to do
    893            when we run into that case.
    894 
    895            We refetch the segment when calling section_symbol, rather
     882        /* Never adjust a reloc against local symbol in a merge section
     883           with non-zero addend.  */
     884        if ((symsec->flags & SEC_MERGE) != 0
     885            && (fixp->fx_offset != 0 || fixp->fx_subsy != NULL))
     886          continue;
     887
     888        /* Never adjust a reloc against TLS local symbol.  */
     889        if ((symsec->flags & SEC_THREAD_LOCAL) != 0)
     890          continue;
     891
     892        /* We refetch the segment when calling section_symbol, rather
    896893           than using symsec, because S_GET_VALUE may wind up changing
    897894           the section when it calls resolve_symbol_value.  */
    898895        fixp->fx_offset += S_GET_VALUE (sym);
    899896        fixp->fx_addsy = section_symbol (S_GET_SEGMENT (sym));
    900         symbol_mark_used_in_reloc (fixp->fx_addsy);
    901897#ifdef DEBUG5
    902898        fprintf (stderr, "\nadjusted fixup:\n");
    903899        print_fixup (fixp);
    904900#endif
    905 
    906       done:
    907         ;
    908901      }
    909 #if 1 /* def RELOC_REQUIRES_SYMBOL  */
    910     else
    911       {
    912         /* There was no symbol required by this relocation.  However,
    913            BFD doesn't really handle relocations without symbols well.
    914            (At least, the COFF support doesn't.)  So for now we fake up
    915            a local symbol in the absolute section.  */
    916 
    917         fixp->fx_addsy = section_symbol (absolute_section);
    918 #if 0
    919         fixp->fx_addsy->sy_used_in_reloc = 1;
    920 #endif
    921       }
    922 #endif
    923902
    924903  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);
    925915}
    926916
     
    943933    return;
    944934
    945   fixup_segment (seginfo->fix_root, sec);
    946 
    947935  n = 0;
    948936  for (fixp = seginfo->fix_root; fixp; fixp = fixp->fx_next)
     
    968956
    969957      /* If this is an undefined symbol which was equated to another
    970          symbol, then use generate the reloc against the latter symbol
     958         symbol, then generate the reloc against the latter symbol
    971959         rather than the former.  */
    972960      sym = fixp->fx_addsy;
    973       while (symbol_equated_p (sym)
    974              && (! S_IS_DEFINED (sym) || S_IS_COMMON (sym)))
     961      while (symbol_equated_reloc_p (sym))
    975962        {
    976963          symbolS *n;
     
    1009996          break;
    1010997        case bfd_reloc_overflow:
    1011           as_bad_where (fixp->fx_file, fixp->fx_line, _("relocation overflow"));
     998          as_bad_where (fixp->fx_file, fixp->fx_line,
     999                        _("relocation overflow"));
    10121000          break;
    10131001        case bfd_reloc_outofrange:
    1014           as_bad_where (fixp->fx_file, fixp->fx_line, _("relocation out of range"));
     1002          as_bad_where (fixp->fx_file, fixp->fx_line,
     1003                        _("relocation out of range"));
    10151004          break;
    10161005        default:
     
    10291018    {
    10301019      arelent **reloc;
    1031       char *data;
    10321020      bfd_reloc_status_type s;
    10331021      symbolS *sym;
     
    10441032         rather than the former.  */
    10451033      sym = fixp->fx_addsy;
    1046       while (symbol_equated_p (sym)
    1047              && (! S_IS_DEFINED (sym) || S_IS_COMMON (sym)))
    1048         sym = symbol_get_value_expression (sym)->X_add_symbol;
     1034      while (symbol_equated_reloc_p (sym))
     1035        {
     1036          symbolS *n;
     1037
     1038          /* We must avoid looping, as that can occur with a badly
     1039             written program.  */
     1040          n = symbol_get_value_expression (sym)->X_add_symbol;
     1041          if (n == sym)
     1042            break;
     1043          fixp->fx_offset += symbol_get_value_expression (sym)->X_add_number;
     1044          sym = n;
     1045        }
    10491046      fixp->fx_addsy = sym;
    10501047
     
    10561053          assert (i <= n);
    10571054        }
    1058       data = fixp->fx_frag->fr_literal + fixp->fx_where;
    10591055      if (fixp->fx_where + fixp->fx_size
    10601056          > fixp->fx_frag->fr_fix + fixp->fx_frag->fr_offset)
     
    10751071                            _("relocation overflow"));
    10761072              break;
     1073            case bfd_reloc_outofrange:
     1074              as_bad_where (fixp->fx_file, fixp->fx_line,
     1075                            _("relocation out of range"));
     1076              break;
    10771077            default:
    1078               as_fatal (_("%s:%u: bad return from bfd_install_relocation"),
    1079                         fixp->fx_file, fixp->fx_line);
     1078              as_fatal (_("%s:%u: bad return from bfd_install_relocation: %x"),
     1079                        fixp->fx_file, fixp->fx_line, s);
    10801080            }
    10811081        }
     
    11601160                                        f->fr_literal, (file_ptr) offset,
    11611161                                        (bfd_size_type) f->fr_fix);
    1162           if (x == false)
     1162          if (!x)
    11631163            {
    11641164              bfd_perror (stdoutput->filename);
     
    11841184                                                (file_ptr) offset,
    11851185                                                (bfd_size_type) fill_size);
    1186                   if (x == false)
     1186                  if (!x)
    11871187                    {
    11881188                      bfd_perror (stdoutput->filename);
     
    12181218                    (stdoutput, sec, buf, (file_ptr) offset,
    12191219                     (bfd_size_type) n_per_buf * fill_size);
    1220                   if (x != true)
    1221                     as_fatal (_("Cannot write to output file."));
     1220                  if (!x)
     1221                    as_fatal (_("cannot write to output file"));
    12221222                  offset += n_per_buf * fill_size;
    12231223                }
     
    13521352  asymbol **asympp;
    13531353  symbolS *symp;
    1354   boolean result;
    1355   extern PTR bfd_alloc PARAMS ((bfd *, size_t));
     1354  bfd_boolean result;
     1355  extern PTR bfd_alloc PARAMS ((bfd *, bfd_size_type));
    13561356
    13571357  /* Count symbols.  We can't rely on a count made by the loop in
     
    13651365    {
    13661366      int i;
    1367 
    1368       asympp = (asymbol **) bfd_alloc (stdoutput,
    1369                                        nsyms * sizeof (asymbol *));
     1367      bfd_size_type amt = (bfd_size_type) nsyms * sizeof (asymbol *);
     1368
     1369      asympp = (asymbol **) bfd_alloc (stdoutput, amt);
    13701370      symp = symbol_rootP;
    13711371      for (i = 0; i < nsyms; i++, symp = symbol_next (symp))
     
    13781378    asympp = 0;
    13791379  result = bfd_set_symtab (stdoutput, asympp, nsyms);
    1380   assert (result == true);
     1380  assert (result);
    13811381  symbol_table_frozen = 1;
    13821382}
    13831383#endif
    1384 
    1385 #if defined (BFD_ASSEMBLER) && defined (OBJ_COFF) && defined (TE_GO32)
    1386 static void
    1387 set_segment_vma (abfd, sec, xxx)
    1388      bfd *abfd;
    1389      asection *sec;
    1390      PTR xxx ATTRIBUTE_UNUSED;
    1391 {
    1392   static bfd_vma addr = 0;
    1393 
    1394   bfd_set_section_vma (abfd, sec, addr);
    1395   addr += bfd_section_size (abfd, sec);
    1396 }
    1397 #endif /* BFD_ASSEMBLER && OBJ_COFF && !TE_PE  */
    13981384
    13991385/* Finish the subsegments.  After every sub-segment, we fake an
     
    14041390
    14051391#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
    14061400#ifdef BFD_ASSEMBLER
    1407 #define SUB_SEGMENT_ALIGN(SEG) (0)
     1401#define SUB_SEGMENT_ALIGN(SEG, FRCHAIN) 0
    14081402#else
    1409 #define SUB_SEGMENT_ALIGN(SEG) (2)
     1403#define SUB_SEGMENT_ALIGN(SEG, FRCHAIN) 2
     1404#endif
    14101405#endif
    14111406#endif
     
    14181413  for (frchainP = frchain_root; frchainP; frchainP = frchainP->frch_next)
    14191414    {
    1420       int alignment;
     1415      int alignment = 0;
    14211416
    14221417      subseg_set (frchainP->frch_seg, frchainP->frch_subseg);
     
    14251420         any alignment is meaningless, and, moreover, will look weird
    14261421         if we are generating a listing.  */
    1427       alignment = had_errors () ? 0 : SUB_SEGMENT_ALIGN (now_seg);
    1428 
    1429       /* The last subsegment gets an aligment corresponding to the
    1430          alignment of the section.  This allows proper nop-filling
    1431          at the end of code-bearing sections.  */
    1432       if (!frchainP->frch_next || frchainP->frch_next->frch_seg != now_seg)
    1433         alignment = get_recorded_alignment (now_seg);
     1422      if (!had_errors ())
     1423        {
     1424          alignment = SUB_SEGMENT_ALIGN (now_seg, frchainP);
     1425#ifdef BFD_ASSEMBLER
     1426          if ((bfd_get_section_flags (now_seg->owner, now_seg) & SEC_MERGE)
     1427              && now_seg->entsize)
     1428            {
     1429              unsigned int entsize = now_seg->entsize;
     1430              int entalign = 0;
     1431
     1432              while ((entsize & 1) == 0)
     1433                {
     1434                  ++entalign;
     1435                  entsize >>= 1;
     1436                }
     1437              if (entalign > alignment)
     1438                alignment = entalign;
     1439            }
     1440#endif
     1441        }
    14341442
    14351443      if (subseg_text_p (now_seg))
     
    14681476      {
    14691477        if (n_warns || n_errs)
    1470           as_warn (_("%d error%s, %d warning%s, generating bad object file.\n"),
     1478          as_warn (_("%d error%s, %d warning%s, generating bad object file"),
    14711479                   n_errs, n_errs == 1 ? "" : "s",
    14721480                   n_warns, n_warns == 1 ? "" : "s");
     
    14751483      {
    14761484        if (n_errs)
    1477           as_fatal (_("%d error%s, %d warning%s, no object file generated.\n"),
     1485          as_fatal (_("%d error%s, %d warning%s, no object file generated"),
    14781486                    n_errs, n_errs == 1 ? "" : "s",
    14791487                    n_warns, n_warns == 1 ? "" : "s");
     
    14941502  /* Remove the sections created by gas for its own purposes.  */
    14951503  {
    1496     asection **seclist, *sec;
     1504    asection **seclist;
    14971505    int i;
    14981506
    14991507    seclist = &stdoutput->sections;
    1500     while (seclist && *seclist)
     1508    while (*seclist)
    15011509      {
    1502         sec = *seclist;
    1503         while (sec == reg_section || sec == expr_section)
     1510        if (*seclist == reg_section || *seclist == expr_section)
    15041511          {
    1505             sec = sec->next;
    1506             *seclist = sec;
     1512            bfd_section_list_remove (stdoutput, seclist);
    15071513            stdoutput->section_count--;
    1508             if (!sec)
    1509               break;
    15101514          }
    1511         if (*seclist)
     1515        else
    15121516          seclist = &(*seclist)->next;
    15131517      }
     
    15341538
    15351539#ifdef BFD_ASSEMBLER
    1536   bfd_map_over_sections (stdoutput, relax_seg, (char *) 1);
    1537   bfd_map_over_sections (stdoutput, relax_seg, (char *) 0);
     1540  while (1)
     1541    {
     1542      int changed;
     1543
     1544#ifndef WORKING_DOT_WORD
     1545      /* We need to reset the markers in the broken word list and
     1546         associated frags between calls to relax_segment (via
     1547         relax_seg).  Since the broken word list is global, we do it
     1548         once per round, rather than locally in relax_segment for each
     1549         segment.  */
     1550      struct broken_word *brokp;
     1551
     1552      for (brokp = broken_words;
     1553           brokp != (struct broken_word *) NULL;
     1554           brokp = brokp->next_broken_word)
     1555        {
     1556          brokp->added = 0;
     1557
     1558          if (brokp->dispfrag != (fragS *) NULL
     1559              && brokp->dispfrag->fr_type == rs_broken_word)
     1560            brokp->dispfrag->fr_subtype = 0;
     1561        }
     1562#endif
     1563
     1564      changed = 0;
     1565      bfd_map_over_sections (stdoutput, relax_seg, &changed);
     1566      if (!changed)
     1567        break;
     1568    }
     1569
     1570  /* Note - Most ports will use the default value of
     1571     TC_FINALIZE_SYMS_BEFORE_SIZE_SEG, which 1.  This will force
     1572     local symbols to be resolved, removing their frag information.
     1573     Some ports however, will not have finished relaxing all of
     1574     their frags and will still need the local symbol frag
     1575     information.  These ports can set
     1576     TC_FINALIZE_SYMS_BEFORE_SIZE_SEG to 0.  */
     1577  finalize_syms = TC_FINALIZE_SYMS_BEFORE_SIZE_SEG;
     1578
    15381579  bfd_map_over_sections (stdoutput, size_seg, (char *) 0);
    15391580#else
     
    15411582#endif /* BFD_ASSEMBLER  */
    15421583
    1543 #if defined (BFD_ASSEMBLER) && defined (OBJ_COFF) && defined (TE_GO32)
    1544   /* Now that the segments have their final sizes, run through the
    1545      sections and set their vma and lma. !BFD gas sets them, and BFD gas
    1546      should too. Currently, only DJGPP uses this code, but other
    1547      COFF targets may need to execute this too.  */
    1548   bfd_map_over_sections (stdoutput, set_segment_vma, (char *) 0);
     1584  /* Relaxation has completed.  Freeze all syms.  */
     1585  finalize_syms = 1;
     1586
     1587#ifdef md_post_relax_hook
     1588  md_post_relax_hook;
    15491589#endif
    15501590
     
    16001640            || fragP->fr_next == data_frag_root
    16011641#endif
    1602             || ((fragP->fr_next->fr_address - fragP->fr_address)
     1642            || ((offsetT) (fragP->fr_next->fr_address - fragP->fr_address)
    16031643                == (fragP->fr_fix + fragP->fr_offset * fragP->fr_var))))
    16041644        abort ();
     
    16951735            /* This is the offset from ??? to table_ptr+0.  */
    16961736            to_addr = table_addr - S_GET_VALUE (lie->sub);
    1697 #ifdef BFD_ASSEMBLER
    1698             to_addr -= symbol_get_frag (lie->sub)->fr_address;
    1699 #endif
    17001737#ifdef TC_CHECK_ADJUSTED_BROKEN_DOT_WORD
    17011738            TC_CHECK_ADJUSTED_BROKEN_DOT_WORD (to_addr, lie);
     
    17141751            from_addr = table_addr;
    17151752            to_addr = S_GET_VALUE (lie->add) + lie->addnum;
    1716 #ifdef BFD_ASSEMBLER
    1717             to_addr += symbol_get_frag (lie->add)->fr_address;
    1718 #endif
    17191753            md_create_long_jump (table_ptr, from_addr, to_addr, lie->dispfrag,
    17201754                                 lie->add);
     
    18341868
    18351869#ifdef BFD_HEADERS
    1836     bfd_seek (stdoutput, 0, 0);
    1837     bfd_write (the_object_file, 1, object_file_size, stdoutput);
     1870    bfd_seek (stdoutput, (file_ptr) 0, 0);
     1871    bfd_bwrite (the_object_file, (bfd_size_type) object_file_size, stdoutput);
    18381872#else
    18391873
     
    18591893
    18601894      for (symp = symbol_rootP; symp; symp = symbol_next (symp))
    1861         resolve_symbol_value (symp, 1);
     1895        resolve_symbol_value (symp);
    18621896    }
    18631897  resolve_local_symbol_values ();
     
    18731907
    18741908  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);
    18751918
    18761919  /* Set up symbol table, and write it out.  */
     
    19011944                 label name.  */
    19021945              if (name2 != name && ! S_IS_DEFINED (symp))
    1903                 as_bad (_("local label %s is not defined"), name2);
     1946                as_bad (_("local label `%s' is not defined"), name2);
    19041947            }
    19051948
     
    19071950             more symbols.  They'll probably only be section symbols,
    19081951             but they'll still need to have the values computed.  */
    1909           resolve_symbol_value (symp, 1);
     1952          resolve_symbol_value (symp);
    19101953
    19111954          /* Skip symbols which were equated to undefined or common
    19121955             symbols.  */
    1913           if (symbol_equated_p (symp)
    1914               && (! S_IS_DEFINED (symp) || S_IS_COMMON (symp)))
     1956          if (symbol_equated_reloc_p (symp))
    19151957            {
    19161958              symbol_remove (symp, &symbol_rootP, &symbol_lastP);
     
    19441986             and symbols that the frob_symbol macros told us to punt,
    19451987             but we keep such symbols if they are used in relocs.  */
    1946           if ((! EMIT_SECTION_SYMBOLS
    1947                && symbol_section_p (symp))
     1988          if (symp == abs_section_sym
     1989              || (! EMIT_SECTION_SYMBOLS
     1990                  && symbol_section_p (symp))
    19481991              /* Note that S_IS_EXTERN and S_IS_LOCAL are not always
    19491992                 opposites.  Sometimes the former checks flags and the
    19501993                 latter examines the name...  */
    19511994              || (!S_IS_EXTERN (symp)
    1952                   && (S_IS_LOCAL (symp) || punt)
     1995                  && (punt || S_IS_LOCAL (symp))
    19531996                  && ! symbol_used_in_reloc_p (symp)))
    19541997            {
     
    19642007          if (! symbol_resolved_p (symp))
    19652008            {
    1966               as_bad (_("can't resolve value for symbol \"%s\""),
     2009              as_bad (_("can't resolve value for symbol `%s'"),
    19672010                      S_GET_NAME (symp));
    19682011              symbol_mark_resolved (symp);
     
    20582101      know (sym_frag != NULL);
    20592102#endif
    2060       know (!(S_GET_SEGMENT (symbolP) == absolute_section)
     2103      know (S_GET_SEGMENT (symbolP) != absolute_section
    20612104            || sym_frag == &zero_address_frag);
    2062       target += S_GET_VALUE (symbolP) + sym_frag->fr_address;
     2105      target += S_GET_VALUE (symbolP);
    20632106
    20642107      /* If frag has yet to be reached on this pass,
     
    21582201   addresses.  */
    21592202
    2160 void
     2203int
    21612204relax_segment (segment_frag_root, segment)
    21622205     struct frag *segment_frag_root;
     
    21652208  register struct frag *fragP;
    21662209  register relax_addressT address;
     2210  int ret;
     2211
    21672212#if !defined (MANY_SEGMENTS) && !defined (BFD_ASSEMBLER)
    21682213  know (segment == SEG_DATA || segment == SEG_TEXT || segment == SEG_BSS);
     
    21972242            if (offset % fragP->fr_var != 0)
    21982243              {
    2199                 as_bad (_("alignment padding (%lu bytes) not a multiple of %ld"),
    2200                         (unsigned long) offset, (long) fragP->fr_var);
     2244                as_bad_where (fragP->fr_file, fragP->fr_line,
     2245                              _("alignment padding (%lu bytes) not a multiple of %ld"),
     2246                              (unsigned long) offset, (long) fragP->fr_var);
    22012247                offset -= (offset % fragP->fr_var);
    22022248              }
     
    22122258
    22132259        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
    22142266          address += md_estimate_size_before_relax (fragP, segment);
    22152267          break;
     
    22982350                        continue;
    22992351
    2300                       offset = (symbol_get_frag (lie->add)->fr_address
    2301                                 + S_GET_VALUE (lie->add)
     2352                      offset = (S_GET_VALUE (lie->add)
    23022353                                + lie->addnum
    2303                                 - (symbol_get_frag (lie->sub)->fr_address
    2304                                    + S_GET_VALUE (lie->sub)));
     2354                                - S_GET_VALUE (lie->sub));
    23052355                      if (offset <= -32768 || offset >= 32767)
    23062356                        {
     
    23092359                              char buf[50];
    23102360                              sprint_value (buf, (addressT) lie->addnum);
    2311                               as_warn (_(".word %s-%s+%s didn't fit"),
    2312                                        S_GET_NAME (lie->add),
    2313                                        S_GET_NAME (lie->sub),
    2314                                        buf);
     2361                              as_warn_where (fragP->fr_file, fragP->fr_line,
     2362                                             _(".word %s-%s+%s didn't fit"),
     2363                                             S_GET_NAME (lie->add),
     2364                                             S_GET_NAME (lie->sub),
     2365                                             buf);
    23152366                            }
    23162367                          lie->added = 1;
     
    23772428                            || (symbolP->sy_frag == &zero_address_frag));
    23782429#endif
    2379                       target += (S_GET_VALUE (symbolP)
    2380                                  + symbol_get_frag (symbolP)->fr_address);
    2381                     }           /* if we have a symbol  */
     2430                      /* Convert from an actual address to an octet offset
     2431                         into the section.  Here it is assumed that the
     2432                         section's VMA is zero, and can omit subtracting it
     2433                         from the symbol's value to get the address offset.  */
     2434                      know (S_GET_SECTION (symbolP)->vma == 0);
     2435                      target += S_GET_VALUE (symbolP) * OCTETS_PER_BYTE;
     2436                    }
    23822437
    23832438                  know (fragP->fr_next);
     
    23902445                         .org backwards.  */
    23912446                      as_bad_where (fragP->fr_file, fragP->fr_line,
    2392                                     _("attempt to .org backwards ignored"));
     2447                                    _("attempt to .org backwards"));
    23932448
    23942449                      /* We've issued an error message.  Change the
     
    24072462
    24082463              case rs_space:
     2464                growth = 0;
    24092465                if (symbolP)
    24102466                  {
    2411                     growth = S_GET_VALUE (symbolP);
    2412                     if (symbol_get_frag (symbolP) != &zero_address_frag
     2467                    offsetT amount;
     2468
     2469                    amount = S_GET_VALUE (symbolP);
     2470                    if (S_GET_SEGMENT (symbolP) != absolute_section
    24132471                        || S_IS_COMMON (symbolP)
    24142472                        || ! S_IS_DEFINED (symbolP))
    2415                       as_bad_where (fragP->fr_file, fragP->fr_line,
    2416                                     _(".space specifies non-absolute value"));
    2417                     fragP->fr_symbol = 0;
    2418                     if (growth < 0)
    24192473                      {
    2420                         as_warn (_(".space or .fill with negative value, ignored"));
    2421                         growth = 0;
     2474                        as_bad_where (fragP->fr_file, fragP->fr_line,
     2475                                      _(".space specifies non-absolute value"));
     2476                        /* Prevent repeat of this error message.  */
     2477                        fragP->fr_symbol = 0;
    24222478                      }
     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);
    24232488                  }
    2424                 else
    2425                   growth = 0;
    24262489                break;
    24272490
     
    24432506                  int size;
    24442507
    2445                   value = resolve_symbol_value (fragP->fr_symbol, 0);
     2508                  value = resolve_symbol_value (fragP->fr_symbol);
    24462509                  size = sizeof_leb128 (value, fragP->fr_subtype);
    24472510                  growth = size - fragP->fr_offset;
     
    24722535  }                             /* do_relax  */
    24732536
    2474   /* We now have valid fr_address'es for each frag.  */
    2475 
    2476   /* All fr_address's are correct, relative to their own segment.
    2477      We have made all the fixS we will ever make.  */
     2537  ret = 0;
     2538  for (fragP = segment_frag_root; fragP; fragP = fragP->fr_next)
     2539    if (fragP->last_fr_address != fragP->fr_address)
     2540      {
     2541        fragP->last_fr_address = fragP->fr_address;
     2542        ret = 1;
     2543      }
     2544  return ret;
    24782545}
    24792546
    24802547#if defined (BFD_ASSEMBLER) || (!defined (BFD) && !defined (OBJ_VMS))
    2481 
    2482 #ifndef TC_RELOC_RTSYM_LOC_FIXUP
    2483 #define TC_RELOC_RTSYM_LOC_FIXUP(X) (1)
    2484 #endif
    24852548
    24862549/* fixup_segment()
     
    24892552   handled now.  (These consist of fixS where we have since discovered
    24902553   the value of a symbol, or the address of the frag involved.)
    2491    For each one, call md_apply_fix to put the fix into the frag data.
     2554   For each one, call md_apply_fix3 to put the fix into the frag data.
    24922555
    24932556   Result is a count of how many relocation structs will be needed to
     
    24962559
    24972560static long
    2498 fixup_segment (fixP, this_segment_type)
    2499      register fixS *fixP;
    2500      segT this_segment_type;    /* N_TYPE bits for segment.  */
     2561fixup_segment (fixP, this_segment)
     2562     fixS *fixP;
     2563     segT this_segment;
    25012564{
    25022565  long seg_reloc_count = 0;
    2503   symbolS *add_symbolP;
    2504   symbolS *sub_symbolP;
    25052566  valueT add_number;
    2506   int size;
    2507   char *place;
    2508   long where;
    2509   int pcrel, plt;
    25102567  fragS *fragP;
    25112568  segT add_symbol_segment = absolute_section;
    25122569
     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
    25132579  /* If the linker is doing the relaxing, we must not do any fixups.
    25142580
    2515      Well, strictly speaking that's not true -- we could do any that are
    2516      PC-relative and don't cross regions that could change size.  And for the
    2517      i960 (the only machine for which we've got a relaxing linker right now),
    2518      we might be able to turn callx/callj into bal anyways in cases where we
    2519      know the maximum displacement.  */
    2520   if (linkrelax && TC_LINKRELAX_FIXUP (this_segment_type))
     2581     Well, strictly speaking that's not true -- we could do any that
     2582     are PC-relative and don't cross regions that could change size.
     2583     And for the i960 we might be able to turn callx/callj into bal
     2584     anyways in cases where we know the maximum displacement.  */
     2585  if (linkrelax && TC_LINKRELAX_FIXUP (this_segment))
    25212586    {
    25222587      for (; fixP; fixP = fixP->fx_next)
    2523         seg_reloc_count++;
     2588        if (!fixP->fx_done)
     2589          {
     2590            if (fixP->fx_addsy == NULL)
     2591              {
     2592                /* There was no symbol required by this relocation.
     2593                   However, BFD doesn't really handle relocations
     2594                   without symbols well. So fake up a local symbol in
     2595                   the absolute section.  */
     2596                fixP->fx_addsy = abs_section_sym;
     2597              }
     2598            symbol_mark_used_in_reloc (fixP->fx_addsy);
     2599            if (fixP->fx_subsy != NULL)
     2600              symbol_mark_used_in_reloc (fixP->fx_subsy);
     2601            seg_reloc_count++;
     2602          }
    25242603      TC_ADJUST_RELOC_COUNT (fixP, seg_reloc_count);
    25252604      return seg_reloc_count;
     
    25352614      fragP = fixP->fx_frag;
    25362615      know (fragP);
    2537       where = fixP->fx_where;
    2538       place = fragP->fr_literal + where;
    2539       size = fixP->fx_size;
    2540       add_symbolP = fixP->fx_addsy;
    25412616#ifdef TC_VALIDATE_FIX
    2542       TC_VALIDATE_FIX (fixP, this_segment_type, skip);
    2543 #endif
    2544       sub_symbolP = fixP->fx_subsy;
     2617      TC_VALIDATE_FIX (fixP, this_segment, skip);
     2618#endif
    25452619      add_number = fixP->fx_offset;
    2546       pcrel = fixP->fx_pcrel;
    2547       plt = fixP->fx_plt;
    2548 
    2549       if (add_symbolP != NULL
    2550           && symbol_mri_common_p (add_symbolP))
     2620
     2621      if (fixP->fx_addsy != NULL
     2622          && symbol_mri_common_p (fixP->fx_addsy))
    25512623        {
    2552           know (add_symbolP->sy_value.X_op == O_symbol);
    2553           add_number += S_GET_VALUE (add_symbolP);
     2624          know (fixP->fx_addsy->sy_value.X_op == O_symbol);
     2625          add_number += S_GET_VALUE (fixP->fx_addsy);
    25542626          fixP->fx_offset = add_number;
    2555           add_symbolP = fixP->fx_addsy =
    2556             symbol_get_value_expression (add_symbolP)->X_add_symbol;
     2627          fixP->fx_addsy
     2628            = symbol_get_value_expression (fixP->fx_addsy)->X_add_symbol;
    25572629        }
    25582630
    2559       if (add_symbolP)
    2560         add_symbol_segment = S_GET_SEGMENT (add_symbolP);
    2561 
    2562       if (sub_symbolP)
     2631      if (fixP->fx_addsy != NULL)
     2632        add_symbol_segment = S_GET_SEGMENT (fixP->fx_addsy);
     2633
     2634      if (fixP->fx_subsy != NULL)
    25632635        {
    2564           resolve_symbol_value (sub_symbolP, 1);
    2565           if (add_symbolP == NULL || add_symbol_segment == absolute_section)
     2636          segT sub_symbol_segment;
     2637          resolve_symbol_value (fixP->fx_subsy);
     2638          sub_symbol_segment = S_GET_SEGMENT (fixP->fx_subsy);
     2639          if (fixP->fx_addsy != NULL
     2640              && sub_symbol_segment == add_symbol_segment
     2641              && !TC_FORCE_RELOCATION_SUB_SAME (fixP, add_symbol_segment))
    25662642            {
    2567               if (add_symbolP != NULL)
    2568                 {
    2569                   add_number += S_GET_VALUE (add_symbolP);
    2570                   add_symbolP = NULL;
    2571                   fixP->fx_addsy = NULL;
    2572                 }
    2573 
    2574               /* It's just -sym.  */
    2575               if (S_GET_SEGMENT (sub_symbolP) == absolute_section)
    2576                 {
    2577                   add_number -= S_GET_VALUE (sub_symbolP);
    2578                   fixP->fx_subsy = NULL;
    2579                 }
    2580               else if (pcrel
    2581                        && S_GET_SEGMENT (sub_symbolP) == this_segment_type)
    2582                 {
    2583                   /* Should try converting to a constant.  */
    2584                   goto bad_sub_reloc;
    2585                 }
    2586               else
    2587               bad_sub_reloc:
    2588                 as_bad_where (fixP->fx_file, fixP->fx_line,
    2589                               _("Negative of non-absolute symbol %s"),
    2590                               S_GET_NAME (sub_symbolP));
     2643              add_number += S_GET_VALUE (fixP->fx_addsy);
     2644              add_number -= S_GET_VALUE (fixP->fx_subsy);
     2645              fixP->fx_offset = add_number;
     2646              /* If the back-end code has selected a pc-relative
     2647                 reloc, adjust the value to be pc-relative.  */
     2648              if (1
     2649#ifdef TC_M68K
     2650                  /* See the comment below about 68k weirdness.  */
     2651                  && 0
     2652#endif
     2653                  && fixP->fx_pcrel)
     2654                add_number -= MD_PCREL_FROM_SECTION (fixP, this_segment);
     2655              fixP->fx_addsy = NULL;
     2656              fixP->fx_subsy = NULL;
     2657              fixP->fx_pcrel = 0;
    25912658            }
    2592           else if (S_GET_SEGMENT (sub_symbolP) == add_symbol_segment
    2593                    && SEG_NORMAL (add_symbol_segment))
     2659          else if (sub_symbol_segment == absolute_section
     2660                   && !TC_FORCE_RELOCATION_SUB_ABS (fixP))
    25942661            {
    2595               /* Difference of 2 symbols from same segment.
    2596                  Can't make difference of 2 undefineds: 'value' means
    2597                  something different for N_UNDF.  */
    2598 #ifdef TC_I960
    2599               /* Makes no sense to use the difference of 2 arbitrary symbols
    2600                  as the target of a call instruction.  */
    2601               if (fixP->fx_tcbit)
    2602                 as_bad_where (fixP->fx_file, fixP->fx_line,
    2603                               _("callj to difference of 2 symbols"));
    2604 #endif /* TC_I960  */
    2605               add_number += S_GET_VALUE (add_symbolP) -
    2606                 S_GET_VALUE (sub_symbolP);
    2607 
    2608               add_symbolP = NULL;
    2609               pcrel = 0;        /* No further pcrel processing.  */
    2610 
    2611               /* Let the target machine make the final determination
    2612                  as to whether or not a relocation will be needed to
    2613                  handle this fixup.  */
    2614               if (!TC_FORCE_RELOCATION_SECTION (fixP, this_segment_type))
    2615                 {
    2616                   fixP->fx_pcrel = 0;
    2617                   fixP->fx_addsy = NULL;
    2618                   fixP->fx_subsy = NULL;
    2619                 }
     2662              add_number -= S_GET_VALUE (fixP->fx_subsy);
     2663              fixP->fx_offset = add_number;
     2664              fixP->fx_subsy = NULL;
    26202665            }
    2621           else
     2666          else if (sub_symbol_segment == this_segment
     2667                   && !TC_FORCE_RELOCATION_SUB_LOCAL (fixP))
    26222668            {
    2623               /* Different segments in subtraction.  */
    2624               know (!(S_IS_EXTERNAL (sub_symbolP)
    2625                       && (S_GET_SEGMENT (sub_symbolP) == absolute_section)));
    2626 
    2627               if ((S_GET_SEGMENT (sub_symbolP) == absolute_section))
    2628                 add_number -= S_GET_VALUE (sub_symbolP);
    2629 
    2630 #ifdef DIFF_EXPR_OK
    2631               else if (S_GET_SEGMENT (sub_symbolP) == this_segment_type
    2632 #if 0
    2633                        /* Do this even if it's already described as
    2634                           pc-relative.  For example, on the m68k, an
    2635                           operand of "pc@(foo-.-2)" should address
    2636                           "foo" in a pc-relative mode.  */
    2637                        && pcrel
    2638 #endif
    2639                        )
    2640                 {
    2641                   /* Make it pc-relative.  */
    2642                   add_number += (MD_PCREL_FROM_SECTION (fixP, this_segment_type)
    2643                                  - S_GET_VALUE (sub_symbolP));
    2644                   pcrel = 1;
    2645                   fixP->fx_pcrel = 1;
    2646                   sub_symbolP = 0;
    2647                   fixP->fx_subsy = 0;
    2648                 }
    2649 #endif
    2650 #ifdef UNDEFINED_DIFFERENCE_OK
    2651               /* The PA needs this for PIC code generation.  We basically
    2652                  don't want to do anything if we have the difference of two
    2653                  symbols at this point.  */
    2654               else if (1)
    2655                 {
    2656                   /* Leave it alone.  */
    2657                 }
    2658 #endif
    2659 #ifdef BFD_ASSEMBLER
    2660               else if (fixP->fx_r_type == BFD_RELOC_GPREL32
    2661                        || fixP->fx_r_type == BFD_RELOC_GPREL16)
    2662                 {
    2663                   /* Leave it alone.  */
    2664                 }
    2665 #endif
    2666               else
    2667                 {
    2668                   char buf[50];
    2669                   sprint_value (buf, fragP->fr_address + where);
    2670                   as_bad_where (fixP->fx_file, fixP->fx_line,
    2671                                 _("Subtraction of two symbols in different sections \"%s\" {%s section} - \"%s\" {%s section} at file address %s."),
    2672                                 S_GET_NAME (add_symbolP),
    2673                                 segment_name (S_GET_SEGMENT (add_symbolP)),
    2674                                 S_GET_NAME (sub_symbolP),
    2675                                 segment_name (S_GET_SEGMENT (sub_symbolP)),
    2676                                 buf);
    2677                 }
     2669              add_number -= S_GET_VALUE (fixP->fx_subsy);
     2670              fixP->fx_offset = (add_number + fixP->fx_dot_value
     2671                                 + fixP->fx_frag->fr_address);
     2672
     2673              /* Make it pc-relative.  If the back-end code has not
     2674                 selected a pc-relative reloc, cancel the adjustment
     2675                 we do later on all pc-relative relocs.  */
     2676              if (0
     2677#ifdef TC_M68K
     2678                  /* Do this for m68k even if it's already described
     2679                     as pc-relative.  On the m68k, an operand of
     2680                     "pc@(foo-.-2)" should address "foo" in a
     2681                     pc-relative mode.  */
     2682                  || 1
     2683#endif
     2684                  || !fixP->fx_pcrel)
     2685                add_number += MD_PCREL_FROM_SECTION (fixP, this_segment);
     2686              fixP->fx_subsy = NULL;
     2687              fixP->fx_pcrel = 1;
     2688            }
     2689          else if (!TC_VALIDATE_FIX_SUB (fixP))
     2690            {
     2691              as_bad_where (fixP->fx_file, fixP->fx_line,
     2692                            _("can't resolve `%s' {%s section} - `%s' {%s section}"),
     2693                            fixP->fx_addsy ? S_GET_NAME (fixP->fx_addsy) : "0",
     2694                            segment_name (add_symbol_segment),
     2695                            S_GET_NAME (fixP->fx_subsy),
     2696                            segment_name (sub_symbol_segment));
    26782697            }
    26792698        }
    26802699
    2681       if (add_symbolP)
     2700      if (fixP->fx_addsy)
    26822701        {
    2683           if (add_symbol_segment == this_segment_type && pcrel && !plt
    2684               && TC_RELOC_RTSYM_LOC_FIXUP (fixP))
     2702          if (add_symbol_segment == this_segment
     2703              && !TC_FORCE_RELOCATION_LOCAL (fixP))
    26852704            {
    26862705              /* This fixup was made when the symbol's segment was
    26872706                 SEG_UNKNOWN, but it is now in the local segment.
    26882707                 So we know how to do the address without relocation.  */
    2689 #ifdef TC_I960
    2690               /* reloc_callj() may replace a 'call' with a 'calls' or a
    2691                  'bal', in which cases it modifies *fixP as appropriate.
    2692                  In the case of a 'calls', no further work is required,
    2693                  and *fixP has been set up to make the rest of the code
    2694                  below a no-op.  */
    2695               reloc_callj (fixP);
    2696 #endif /* TC_I960  */
    2697 
    2698               add_number += S_GET_VALUE (add_symbolP);
    2699               add_number -= MD_PCREL_FROM_SECTION (fixP, this_segment_type);
    2700               /* Lie.  Don't want further pcrel processing.  */
    2701               pcrel = 0;
    2702 
    2703               /* Let the target machine make the final determination
    2704                  as to whether or not a relocation will be needed to
    2705                  handle this fixup.  */
    2706               if (!TC_FORCE_RELOCATION (fixP))
    2707                 {
    2708                   fixP->fx_pcrel = 0;
    2709                   fixP->fx_addsy = NULL;
    2710                 }
     2708              add_number += S_GET_VALUE (fixP->fx_addsy);
     2709              fixP->fx_offset = add_number;
     2710              if (fixP->fx_pcrel)
     2711                add_number -= MD_PCREL_FROM_SECTION (fixP, this_segment);
     2712              fixP->fx_addsy = NULL;
     2713              fixP->fx_pcrel = 0;
    27112714            }
    2712           else
     2715          else if (add_symbol_segment == absolute_section
     2716                   && !TC_FORCE_RELOCATION_ABS (fixP))
    27132717            {
    2714               if (add_symbol_segment == absolute_section
    2715                   && ! pcrel)
    2716                 {
    2717 #ifdef TC_I960
    2718                   /* See comment about reloc_callj() above.  */
    2719                   reloc_callj (fixP);
    2720 #endif /* TC_I960  */
    2721                   add_number += S_GET_VALUE (add_symbolP);
    2722 
    2723                   /* Let the target machine make the final determination
    2724                      as to whether or not a relocation will be needed to
    2725                      handle this fixup.  */
    2726 
    2727                   if (!TC_FORCE_RELOCATION (fixP))
    2728                     {
    2729                       fixP->fx_addsy = NULL;
    2730                       add_symbolP = NULL;
    2731                     }
    2732                 }
    2733               else if (add_symbol_segment == undefined_section
     2718              add_number += S_GET_VALUE (fixP->fx_addsy);
     2719              fixP->fx_offset = add_number;
     2720              fixP->fx_addsy = NULL;
     2721            }
     2722          else if (add_symbol_segment != undefined_section
    27342723#ifdef BFD_ASSEMBLER
    2735                        || bfd_is_com_section (add_symbol_segment)
    2736 #endif
    2737                        )
    2738                 {
    2739 #ifdef TC_I960
    2740                   if ((int) fixP->fx_bit_fixP == 13)
    2741                     {
    2742                       /* This is a COBR instruction.  They have only a
    2743                          13-bit displacement and are only to be used
    2744                          for local branches: flag as error, don't generate
    2745                          relocation.  */
    2746                       as_bad_where (fixP->fx_file, fixP->fx_line,
    2747                                     _("can't use COBR format with external label"));
    2748                       fixP->fx_addsy = NULL;
    2749                       fixP->fx_done = 1;
    2750                       continue;
    2751                     }           /* COBR.  */
    2752 #endif /* TC_I960  */
    2753 
    2754 #ifdef OBJ_COFF
    2755 #ifdef TE_I386AIX
    2756                   if (S_IS_COMMON (add_symbolP))
    2757                     add_number += S_GET_VALUE (add_symbolP);
    2758 #endif /* TE_I386AIX  */
    2759 #endif /* OBJ_COFF  */
    2760                   ++seg_reloc_count;
    2761                 }
    2762               else
    2763                 {
    2764                   seg_reloc_count++;
    2765                   if (TC_FIX_ADJUSTABLE (fixP))
    2766                     add_number += S_GET_VALUE (add_symbolP);
    2767                 }
     2724                   && ! bfd_is_com_section (add_symbol_segment)
     2725#endif
     2726                   && MD_APPLY_SYM_VALUE (fixP))
     2727            add_number += S_GET_VALUE (fixP->fx_addsy);
     2728        }
     2729
     2730      if (fixP->fx_pcrel)
     2731        {
     2732          add_number -= MD_PCREL_FROM_SECTION (fixP, this_segment);
     2733          if (!fixP->fx_done && fixP->fx_addsy == NULL)
     2734            {
     2735              /* There was no symbol required by this relocation.
     2736                 However, BFD doesn't really handle relocations
     2737                 without symbols well. So fake up a local symbol in
     2738                 the absolute section.  */
     2739              fixP->fx_addsy = abs_section_sym;
    27682740            }
    27692741        }
    27702742
    2771       if (pcrel)
    2772         {
    2773           add_number -= MD_PCREL_FROM_SECTION (fixP, this_segment_type);
    2774           if (add_symbolP == 0)
    2775             {
    2776 #ifndef BFD_ASSEMBLER
    2777               fixP->fx_addsy = &abs_symbol;
    2778 #else
    2779               fixP->fx_addsy = section_symbol (absolute_section);
    2780 #endif
    2781               symbol_mark_used_in_reloc (fixP->fx_addsy);
    2782               ++seg_reloc_count;
    2783             }
    2784         }
     2743      if (!fixP->fx_done)
     2744        md_apply_fix3 (fixP, &add_number, this_segment);
    27852745
    27862746      if (!fixP->fx_done)
    27872747        {
    2788 #ifdef MD_APPLY_FIX3
    2789           md_apply_fix3 (fixP, &add_number, this_segment_type);
    2790 #else
    2791 #ifdef BFD_ASSEMBLER
    2792           md_apply_fix (fixP, &add_number);
    2793 #else
    2794           md_apply_fix (fixP, add_number);
    2795 #endif
    2796 #endif
    2797 
    2798 #ifndef TC_HANDLES_FX_DONE
    2799           /* If the tc-* files haven't been converted, assume it's handling
    2800              it the old way, where a null fx_addsy means that the fix has
    2801              been applied completely, and no further work is needed.  */
    2802           if (fixP->fx_addsy == 0 && fixP->fx_pcrel == 0)
    2803             fixP->fx_done = 1;
    2804 #endif
     2748          ++seg_reloc_count;
     2749          if (fixP->fx_addsy == NULL)
     2750            fixP->fx_addsy = abs_section_sym;
     2751          symbol_mark_used_in_reloc (fixP->fx_addsy);
     2752          if (fixP->fx_subsy != NULL)
     2753            symbol_mark_used_in_reloc (fixP->fx_subsy);
    28052754        }
    28062755
    2807       if (!fixP->fx_bit_fixP && !fixP->fx_no_overflow && size > 0)
     2756      if (!fixP->fx_bit_fixP && !fixP->fx_no_overflow && fixP->fx_size != 0)
    28082757        {
    2809           if ((size_t) size < sizeof (valueT))
     2758          if (fixP->fx_size < sizeof (valueT))
    28102759            {
    28112760              valueT mask;
     
    28132762              mask = 0;
    28142763              mask--;           /* Set all bits to one.  */
    2815               mask <<= size * 8 - (fixP->fx_signed ? 1 : 0);
     2764              mask <<= fixP->fx_size * 8 - (fixP->fx_signed ? 1 : 0);
    28162765              if ((add_number & mask) != 0 && (add_number & mask) != mask)
    28172766                {
    28182767                  char buf[50], buf2[50];
    2819                   sprint_value (buf, fragP->fr_address + where);
     2768                  sprint_value (buf, fragP->fr_address + fixP->fx_where);
    28202769                  if (add_number > 1000)
    28212770                    sprint_value (buf2, add_number);
     
    28232772                    sprintf (buf2, "%ld", (long) add_number);
    28242773                  as_bad_where (fixP->fx_file, fixP->fx_line,
    2825                                 _("Value of %s too large for field of %d bytes at %s"),
    2826                                 buf2, size, buf);
     2774                                _("value of %s too large for field of %d bytes at %s"),
     2775                                buf2, fixP->fx_size, buf);
    28272776                } /* Generic error checking.  */
    28282777            }
     
    28322781             catch over-large switches generated by gcc on the 68k.  */
    28332782          if (!flag_signed_overflow_ok
    2834               && size == 2
     2783              && fixP->fx_size == 2
    28352784              && add_number > 0x7fff)
    28362785            as_bad_where (fixP->fx_file, fixP->fx_line,
    2837                           _("Signed .word overflow; switch may be too large; %ld at 0x%lx"),
     2786                          _("signed .word overflow; switch may be too large; %ld at 0x%lx"),
    28382787                          (long) add_number,
    2839                           (unsigned long) (fragP->fr_address + where));
     2788                          (long) (fragP->fr_address + fixP->fx_where));
    28402789#endif
    28412790        }                       /* Not a bit fix.  */
     
    28632812     int n;
    28642813{
    2865   if ((size_t) n > sizeof (val) || n <= 0)
     2814  if (n <= 0)
    28662815    abort ();
    28672816  while (n--)
     
    28782827     int n;
    28792828{
    2880   if ((size_t) n > sizeof (val) || n <= 0)
     2829  if (n <= 0)
    28812830    abort ();
    28822831  while (n--)
Note: See TracChangeset for help on using the changeset viewer.