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/symbols.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    11/* symbols.c -symbol table-
    22   Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
    3    1999, 2000, 2001
     3   1999, 2000, 2001, 2002, 2003
    44   Free Software Foundation, Inc.
    55
     
    2323/* #define DEBUG_SYMS / * to debug symbol list maintenance.  */
    2424
    25 #include <ctype.h>
    26 
    2725#include "as.h"
    2826
     27#include "safe-ctype.h"
    2928#include "obstack.h"            /* For "symbols.h" */
    3029#include "subsegs.h"
     
    6261struct obstack notes;
    6362
     63static char *save_symbol_name PARAMS ((const char *));
    6464static void fb_label_init PARAMS ((void));
    6565static long dollar_label_instance PARAMS ((long));
     
    6767
    6868static void print_binary PARAMS ((FILE *, const char *, expressionS *));
     69static void report_op_error PARAMS ((symbolS *, symbolS *, symbolS *));
    6970
    7071/* Return a pointer to a new symbol.  Die if we can't make a new
     
    124125  if (! symbols_case_sensitive)
    125126    {
    126       unsigned char *s;
    127 
    128       for (s = (unsigned char *) ret; *s != '\0'; s++)
    129         if (islower (*s))
    130           *s = toupper (*s);
     127      char *s;
     128
     129      for (s = ret; *s != '\0'; s++)
     130        *s = TOUPPER (*s);
    131131    }
    132132
     
    208208
    209209static struct local_symbol *
    210 local_symbol_make (name, section, offset, frag)
     210local_symbol_make (name, section, value, frag)
    211211     const char *name;
    212212     segT section;
    213      valueT offset;
     213     valueT value;
    214214     fragS *frag;
    215215{
     
    226226  ret->lsy_section = section;
    227227  local_symbol_set_frag (ret, frag);
    228   ret->lsy_offset = offset;
     228  ret->lsy_value = value;
    229229
    230230  hash_jam (local_hash, name_copy, (PTR) ret);
     
    248248  ++local_symbol_conversion_count;
    249249
    250   ret = symbol_new (locsym->lsy_name, locsym->lsy_section, locsym->lsy_offset,
     250  ret = symbol_new (locsym->lsy_name, locsym->lsy_section, locsym->lsy_value,
    251251                    local_symbol_get_frag (locsym));
    252252
     
    256256  /* Local symbols are always either defined or used.  */
    257257  ret->sy_used = 1;
     258
     259#ifdef TC_LOCAL_SYMFIELD_CONVERT
     260  TC_LOCAL_SYMFIELD_CONVERT (locsym, ret);
     261#endif
    258262
    259263  symbol_table_insert (ret);
     
    313317      extern const int md_short_jump_size;
    314318      extern const int md_long_jump_size;
     319
     320      if (now_seg == absolute_section)
     321        {
     322          as_bad (_("cannot define symbol `%s' in absolute section"), sym_name);
     323          return NULL;
     324        }
     325
    315326      possible_bytes = (md_short_jump_size
    316327                        + new_broken_words * md_long_jump_size);
     
    356367              && (local_symbol_get_frag (locsym) != frag_now
    357368                  || locsym->lsy_section != now_seg
    358                   || locsym->lsy_offset != frag_now_fix ()))
     369                  || locsym->lsy_value != frag_now_fix ()))
    359370            {
    360               as_bad (_("Symbol %s already defined."), sym_name);
     371              as_bad (_("symbol `%s' is already defined"), sym_name);
    361372              return symbolP;
    362373            }
     
    364375          locsym->lsy_section = now_seg;
    365376          local_symbol_set_frag (locsym, frag_now);
    366           locsym->lsy_offset = frag_now_fix ();
     377          locsym->lsy_value = frag_now_fix ();
    367378#endif
    368379        }
     
    439450                  if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
    440451#endif
    441                     sprintf(od_buf, "%d.%d.",
    442                             S_GET_OTHER (symbolP),
    443                             S_GET_DESC (symbolP));
    444 #endif
    445                   as_bad (_("Symbol \"%s\" is already defined as \"%s\"/%s%ld."),
     452                    sprintf (od_buf, "%d.%d.",
     453                             S_GET_OTHER (symbolP),
     454                             S_GET_DESC (symbolP));
     455#endif
     456                  as_bad (_("symbol `%s' is already defined as \"%s\"/%s%ld"),
    446457                            sym_name,
    447458                            segment_name (S_GET_SEGMENT (symbolP)),
     
    457468                && S_GET_VALUE (symbolP) == frag_now_fix ()
    458469                && S_GET_SEGMENT (symbolP) == now_seg))
    459             as_bad (_("Symbol %s already defined."), sym_name);
     470            as_bad (_("symbol `%s' is already defined"), sym_name);
    460471        }
    461472
     
    483494    {
    484495      /* This symbol is actually being defined within an MRI common
    485         section.  This requires special handling.  */
     496        section.  This requires special handling.  */
    486497      if (LOCAL_SYMBOL_CHECK (symbolP))
    487498        symbolP = local_symbol_convert ((struct local_symbol *) symbolP);
     
    521532                               (PTR) symbolP);
    522533      if (error_string != NULL)
    523         as_fatal (_("Inserting \"%s\" into symbol table failed: %s"),
     534        as_fatal (_("inserting \"%s\" into symbol table failed: %s"),
    524535                  S_GET_NAME (symbolP), error_string);
    525536      return;
     
    528539  if ((error_string = hash_jam (sy_hash, S_GET_NAME (symbolP), (PTR) symbolP)))
    529540    {
    530       as_fatal (_("Inserting \"%s\" into symbol table failed: %s"),
     541      as_fatal (_("inserting \"%s\" into symbol table failed: %s"),
    531542                S_GET_NAME (symbolP), error_string);
    532543    }                           /* on error  */
     
    571582symbolS *
    572583symbol_make (name)
    573      CONST char *name;
     584     const char *name;
    574585{
    575586  symbolS *symbolP;
     
    591602symbolS *
    592603symbol_find (name)
    593      CONST char *name;
     604     const char *name;
    594605{
    595606#ifdef STRIP_UNDERSCORE
     
    601612
    602613symbolS *
     614symbol_find_exact (name)
     615     const char *name;
     616{
     617#ifdef BFD_ASSEMBLER
     618  {
     619    struct local_symbol *locsym;
     620
     621    locsym = (struct local_symbol *) hash_find (local_hash, name);
     622    if (locsym != NULL)
     623      return (symbolS *) locsym;
     624  }
     625#endif
     626
     627  return ((symbolS *) hash_find (sy_hash, name));
     628}
     629
     630symbolS *
    603631symbol_find_base (name, strip_underscore)
    604      CONST char *name;
     632     const char *name;
    605633     int strip_underscore;
    606634{
     
    630658      while ((c = *orig++) != '\0')
    631659        {
    632           if (islower (c))
    633             c = toupper (c);
    634           *copy++ = c;
     660          *copy++ = TOUPPER (c);
    635661        }
    636662      *copy = '\0';
    637663    }
    638664
    639 #ifdef BFD_ASSEMBLER
    640   {
    641     struct local_symbol *locsym;
    642 
    643     locsym = (struct local_symbol *) hash_find (local_hash, name);
    644     if (locsym != NULL)
    645       return (symbolS *) locsym;
    646   }
    647 #endif
    648 
    649   return ((symbolS *) hash_find (sy_hash, name));
     665  return symbol_find_exact (name);
    650666}
    651667
     
    827843}
    828844
     845static void
     846report_op_error (symp, left, right)
     847     symbolS *symp;
     848     symbolS *left, *right;
     849{
     850  char *file;
     851  unsigned int line;
     852  segT seg_left = S_GET_SEGMENT (left);
     853  segT seg_right = right ? S_GET_SEGMENT (right) : 0;
     854
     855  if (expr_symbol_where (symp, &file, &line))
     856    {
     857      if (seg_left == undefined_section)
     858        as_bad_where (file, line,
     859                      _("undefined symbol `%s' in operation"),
     860                      S_GET_NAME (left));
     861      if (seg_right == undefined_section)
     862        as_bad_where (file, line,
     863                      _("undefined symbol `%s' in operation"),
     864                      S_GET_NAME (right));
     865      if (seg_left != undefined_section
     866          && seg_right != undefined_section)
     867        {
     868          if (right)
     869            as_bad_where (file, line,
     870                          _("invalid sections for operation on `%s' and `%s'"),
     871                          S_GET_NAME (left), S_GET_NAME (right));
     872          else
     873            as_bad_where (file, line,
     874                          _("invalid section for operation on `%s'"),
     875                          S_GET_NAME (left));
     876        }
     877
     878    }
     879  else
     880    {
     881      if (seg_left == undefined_section)
     882        as_bad (_("undefined symbol `%s' in operation setting `%s'"),
     883                S_GET_NAME (left), S_GET_NAME (symp));
     884      if (seg_right == undefined_section)
     885        as_bad (_("undefined symbol `%s' in operation setting `%s'"),
     886                S_GET_NAME (right), S_GET_NAME (symp));
     887      if (seg_left != undefined_section
     888          && seg_right != undefined_section)
     889        {
     890          if (right)
     891            as_bad_where (file, line,
     892                          _("invalid sections for operation on `%s' and `%s' setting `%s'"),
     893                          S_GET_NAME (left), S_GET_NAME (right), S_GET_NAME (symp));
     894          else
     895            as_bad_where (file, line,
     896                          _("invalid section for operation on `%s' setting `%s'"),
     897                          S_GET_NAME (left), S_GET_NAME (symp));
     898        }
     899    }
     900}
     901
    829902/* Resolve the value of a symbol.  This is called during the final
    830903   pass over the symbol table to resolve any symbols with complex
     
    832905
    833906valueT
    834 resolve_symbol_value (symp, finalize)
     907resolve_symbol_value (symp)
    835908     symbolS *symp;
    836      int finalize;
    837909{
    838910  int resolved;
    839   valueT final_val;
     911  valueT final_val = 0;
    840912  segT final_seg;
    841913
     
    845917      struct local_symbol *locsym = (struct local_symbol *) symp;
    846918
     919      final_val = locsym->lsy_value;
    847920      if (local_symbol_resolved_p (locsym))
    848         return locsym->lsy_offset / bfd_octets_per_byte (stdoutput);
    849 
    850       final_val = (local_symbol_get_frag (locsym)->fr_address
    851                    + locsym->lsy_offset) / bfd_octets_per_byte (stdoutput);
    852 
    853       if (finalize)
     921        return final_val;
     922
     923      final_val += local_symbol_get_frag (locsym)->fr_address / OCTETS_PER_BYTE;
     924
     925      if (finalize_syms)
    854926        {
    855           locsym->lsy_offset = final_val;
     927          locsym->lsy_value = final_val;
    856928          local_symbol_mark_resolved (locsym);
    857929        }
     
    874946  if (symp->sy_resolving)
    875947    {
    876       if (finalize)
    877         as_bad (_("Symbol definition loop encountered at %s"),
     948      if (finalize_syms)
     949        as_bad (_("symbol definition loop encountered at `%s'"),
    878950                S_GET_NAME (symp));
    879951      final_val = 0;
     
    914986        case O_symbol:
    915987        case O_symbol_rva:
    916           left = resolve_symbol_value (add_symbol, finalize);
     988          left = resolve_symbol_value (add_symbol);
     989          seg_left = S_GET_SEGMENT (add_symbol);
     990          if (finalize_syms)
     991            symp->sy_value.X_op_symbol = NULL;
     992
    917993        do_symbol:
    918 
    919994          if (symp->sy_mri_common)
    920995            {
    921996              /* This is a symbol inside an MRI common section.  The
    922                 relocation routines are going to handle it specially.
    923                 Don't change the value.  */
     997                relocation routines are going to handle it specially.
     998                Don't change the value.  */
    924999              resolved = symbol_resolved_p (add_symbol);
    9251000              break;
    9261001            }
    9271002
    928           if (finalize && final_val == 0)
     1003          if (finalize_syms && final_val == 0)
    9291004            {
    9301005              if (LOCAL_SYMBOL_CHECK (add_symbol))
     
    9341009            }
    9351010
    936           /* If we have equated this symbol to an undefined symbol, we
    937              keep X_op set to O_symbol, and we don't change
    938              X_add_number.  This permits the routine which writes out
    939              relocation to detect this case, and convert the
    940              relocation to be against the symbol to which this symbol
    941              is equated.  */
     1011          /* If we have equated this symbol to an undefined or common
     1012             symbol, keep X_op set to O_symbol, and don't change
     1013             X_add_number.  This permits the routine which writes out
     1014             relocation to detect this case, and convert the
     1015             relocation to be against the symbol to which this symbol
     1016             is equated.  */
    9421017          if (! S_IS_DEFINED (add_symbol) || S_IS_COMMON (add_symbol))
    9431018            {
    944               if (finalize)
     1019              if (finalize_syms)
    9451020                {
    946                   S_SET_SEGMENT (symp, S_GET_SEGMENT (add_symbol));
    9471021                  symp->sy_value.X_op = O_symbol;
    9481022                  symp->sy_value.X_add_symbol = add_symbol;
    9491023                  symp->sy_value.X_add_number = final_val;
     1024                  /* Use X_op_symbol as a flag.  */
     1025                  symp->sy_value.X_op_symbol = add_symbol;
     1026                  final_seg = seg_left;
    9501027                }
    9511028              final_val = 0;
    9521029              resolved = symbol_resolved_p (add_symbol);
     1030              symp->sy_resolving = 0;
     1031              goto exit_dont_set_value;
     1032            }
     1033          else if (finalize_syms && final_seg == expr_section
     1034                   && seg_left != expr_section)
     1035            {
     1036              /* If the symbol is an expression symbol, do similarly
     1037                 as for undefined and common syms above.  Handles
     1038                 "sym +/- expr" where "expr" cannot be evaluated
     1039                 immediately, and we want relocations to be against
     1040                 "sym", eg. because it is weak.  */
     1041              symp->sy_value.X_op = O_symbol;
     1042              symp->sy_value.X_add_symbol = add_symbol;
     1043              symp->sy_value.X_add_number = final_val;
     1044              symp->sy_value.X_op_symbol = add_symbol;
     1045              final_seg = seg_left;
     1046              final_val += symp->sy_frag->fr_address + left;
     1047              resolved = symbol_resolved_p (add_symbol);
     1048              symp->sy_resolving = 0;
    9531049              goto exit_dont_set_value;
    9541050            }
     
    9571053              final_val += symp->sy_frag->fr_address + left;
    9581054              if (final_seg == expr_section || final_seg == undefined_section)
    959                 final_seg = S_GET_SEGMENT (add_symbol);
     1055                final_seg = seg_left;
    9601056            }
    9611057
     
    9661062        case O_bit_not:
    9671063        case O_logical_not:
    968           left = resolve_symbol_value (add_symbol, finalize);
     1064          left = resolve_symbol_value (add_symbol);
     1065          seg_left = S_GET_SEGMENT (add_symbol);
     1066
     1067          /* By reducing these to the relevant dyadic operator, we get
     1068                !S -> S == 0    permitted on anything,
     1069                -S -> 0 - S     only permitted on absolute
     1070                ~S -> S ^ ~0    only permitted on absolute  */
     1071          if (op != O_logical_not && seg_left != absolute_section
     1072              && finalize_syms)
     1073            report_op_error (symp, add_symbol, NULL);
     1074
     1075          if (final_seg == expr_section || final_seg == undefined_section)
     1076            final_seg = absolute_section;
    9691077
    9701078          if (op == O_uminus)
     
    9761084
    9771085          final_val += left + symp->sy_frag->fr_address;
    978           if (final_seg == expr_section || final_seg == undefined_section)
    979             final_seg = absolute_section;
    9801086
    9811087          resolved = symbol_resolved_p (add_symbol);
     
    10011107        case O_logical_and:
    10021108        case O_logical_or:
    1003           left = resolve_symbol_value (add_symbol, finalize);
    1004           right = resolve_symbol_value (op_symbol, finalize);
     1109          left = resolve_symbol_value (add_symbol);
     1110          right = resolve_symbol_value (op_symbol);
    10051111          seg_left = S_GET_SEGMENT (add_symbol);
    10061112          seg_right = S_GET_SEGMENT (op_symbol);
     
    10081114          /* Simplify addition or subtraction of a constant by folding the
    10091115             constant into X_add_number.  */
    1010           if (op == O_add || op == O_subtract)
     1116          if (op == O_add)
    10111117            {
    10121118              if (seg_right == absolute_section)
    10131119                {
    1014                   if (op == O_add)
    1015                     final_val += right;
    1016                   else
    1017                     final_val -= right;
    1018                   op = O_symbol;
    1019                   op_symbol = NULL;
     1120                  final_val += right;
    10201121                  goto do_symbol;
    10211122                }
    1022               else if (seg_left == absolute_section && op == O_add)
     1123              else if (seg_left == absolute_section)
    10231124                {
    1024                   op = O_symbol;
    10251125                  final_val += left;
    10261126                  add_symbol = op_symbol;
    10271127                  left = right;
    1028                   op_symbol = NULL;
     1128                  seg_left = seg_right;
    10291129                  goto do_symbol;
    10301130                }
    10311131            }
    1032 
    1033           /* Subtraction is permitted if both operands are in the same
    1034              section.  Otherwise, both operands must be absolute.  We
    1035              already handled the case of addition or subtraction of a
    1036              constant above.  This will probably need to be changed
    1037              for an object file format which supports arbitrary
    1038              expressions, such as IEEE-695.  */
    1039           /* Don't emit messages unless we're finalizing the symbol value,
    1040              otherwise we may get the same message multiple times.  */
    1041           if ((seg_left != absolute_section
    1042                || seg_right != absolute_section)
    1043               && (op != O_subtract
    1044                   || seg_left != seg_right
    1045                   || seg_left == undefined_section)
    1046               && finalize)
     1132          else if (op == O_subtract)
    10471133            {
    1048               char *file;
    1049               unsigned int line;
    1050 
    1051               if (expr_symbol_where (symp, &file, &line))
     1134              if (seg_right == absolute_section)
    10521135                {
    1053                   if (seg_left == undefined_section)
    1054                     as_bad_where (file, line,
    1055                                   _("undefined symbol %s in operation"),
    1056                                   S_GET_NAME (symp->sy_value.X_add_symbol));
    1057                   if (seg_right == undefined_section)
    1058                     as_bad_where (file, line,
    1059                                   _("undefined symbol %s in operation"),
    1060                                   S_GET_NAME (symp->sy_value.X_op_symbol));
    1061                   if (seg_left != undefined_section
    1062                       && seg_right != undefined_section)
    1063                     as_bad_where (file, line,
    1064                                   _("invalid section for operation"));
    1065                 }
    1066               else
    1067                 {
    1068                   if (seg_left == undefined_section)
    1069                     as_bad (_("undefined symbol %s in operation setting %s"),
    1070                             S_GET_NAME (symp->sy_value.X_add_symbol),
    1071                             S_GET_NAME (symp));
    1072                   if (seg_right == undefined_section)
    1073                     as_bad (_("undefined symbol %s in operation setting %s"),
    1074                             S_GET_NAME (symp->sy_value.X_op_symbol),
    1075                             S_GET_NAME (symp));
    1076                   if (seg_left != undefined_section
    1077                       && seg_right != undefined_section)
    1078                     as_bad (_("invalid section for operation setting %s"),
    1079                             S_GET_NAME (symp));
     1136                  final_val -= right;
     1137                  goto do_symbol;
    10801138                }
    10811139            }
     1140
     1141          /* Equality and non-equality tests are permitted on anything.
     1142             Subtraction, and other comparison operators are permitted if
     1143             both operands are in the same section.  Otherwise, both
     1144             operands must be absolute.  We already handled the case of
     1145             addition or subtraction of a constant above.  This will
     1146             probably need to be changed for an object file format which
     1147             supports arbitrary expressions, such as IEEE-695.
     1148
     1149             Don't emit messages unless we're finalizing the symbol value,
     1150             otherwise we may get the same message multiple times.  */
     1151          if (finalize_syms
     1152              && !(seg_left == absolute_section
     1153                   && seg_right == absolute_section)
     1154              && !(op == O_eq || op == O_ne)
     1155              && !((op == O_subtract
     1156                    || op == O_lt || op == O_le || op == O_ge || op == O_gt)
     1157                   && seg_left == seg_right
     1158                   && (seg_left != undefined_section
     1159                       || add_symbol == op_symbol)))
     1160            report_op_error (symp, add_symbol, op_symbol);
     1161
     1162          if (final_seg == expr_section || final_seg == undefined_section)
     1163            final_seg = absolute_section;
    10821164
    10831165          /* Check for division by zero.  */
     
    10851167            {
    10861168              /* If seg_right is not absolute_section, then we've
    1087                 already issued a warning about using a bad symbol.  */
    1088               if (seg_right == absolute_section && finalize)
     1169                already issued a warning about using a bad symbol.  */
     1170              if (seg_right == absolute_section && finalize_syms)
    10891171                {
    10901172                  char *file;
     
    10941176                    as_bad_where (file, line, _("division by zero"));
    10951177                  else
    1096                     as_bad (_("division by zero when setting %s"),
     1178                    as_bad (_("division by zero when setting `%s'"),
    10971179                            S_GET_NAME (symp));
    10981180                }
     
    11141196            case O_add:                 left += right; break;
    11151197            case O_subtract:            left -= right; break;
    1116             case O_eq:  left = left == right ? ~ (offsetT) 0 : 0; break;
    1117             case O_ne:  left = left != right ? ~ (offsetT) 0 : 0; break;
     1198            case O_eq:
     1199            case O_ne:
     1200              left = (left == right && seg_left == seg_right
     1201                      && (seg_left != undefined_section
     1202                          || add_symbol == op_symbol)
     1203                      ? ~ (offsetT) 0 : 0);
     1204              if (symp->sy_value.X_op == O_ne)
     1205                left = ~left;
     1206              break;
    11181207            case O_lt:  left = left <  right ? ~ (offsetT) 0 : 0; break;
    11191208            case O_le:  left = left <= right ? ~ (offsetT) 0 : 0; break;
     
    11271216          final_val += symp->sy_frag->fr_address + left;
    11281217          if (final_seg == expr_section || final_seg == undefined_section)
    1129             final_seg = absolute_section;
     1218            {
     1219              if (seg_left == undefined_section
     1220                  || seg_right == undefined_section)
     1221                final_seg = undefined_section;
     1222              else if (seg_left == absolute_section)
     1223                final_seg = seg_right;
     1224              else
     1225                final_seg = seg_left;
     1226            }
    11301227          resolved = (symbol_resolved_p (add_symbol)
    11311228                      && symbol_resolved_p (op_symbol));
     
    11461243    }
    11471244
    1148   if (finalize)
    1149     {
    1150       S_SET_VALUE (symp, final_val);
    1151 
     1245  if (finalize_syms)
     1246    S_SET_VALUE (symp, final_val);
     1247
     1248exit_dont_set_value:
     1249  /* Always set the segment, even if not finalizing the value.
     1250     The segment is used to determine whether a symbol is defined.  */
    11521251#if defined (OBJ_AOUT) && ! defined (BFD_ASSEMBLER)
    1153       /* The old a.out backend does not handle S_SET_SEGMENT correctly
    1154          for a stab symbol, so we use this bad hack.  */
    1155       if (final_seg != S_GET_SEGMENT (symp))
    1156 #endif
    1157         S_SET_SEGMENT (symp, final_seg);
    1158     }
    1159 
    1160 exit_dont_set_value:
     1252  /* The old a.out backend does not handle S_SET_SEGMENT correctly
     1253     for a stab symbol, so we use this bad hack.  */
     1254  if (final_seg != S_GET_SEGMENT (symp))
     1255#endif
     1256    S_SET_SEGMENT (symp, final_seg);
     1257
    11611258  /* Don't worry if we can't resolve an expr_section symbol.  */
    1162   if (finalize)
     1259  if (finalize_syms)
    11631260    {
    11641261      if (resolved)
     
    11661263      else if (S_GET_SEGMENT (symp) != expr_section)
    11671264        {
    1168           as_bad (_("can't resolve value for symbol \"%s\""),
     1265          as_bad (_("can't resolve value for symbol `%s'"),
    11691266                  S_GET_NAME (symp));
    11701267          symp->sy_resolved = 1;
     
    11871284{
    11881285  if (value != NULL)
    1189     resolve_symbol_value (value, 1);
     1286    resolve_symbol_value (value);
    11901287}
    11911288
     
    15471644    return s;
    15481645
    1549   for (label_number = 0, p = s + index + 1; isdigit ((unsigned char) *p); ++p)
     1646  for (label_number = 0, p = s + index + 1; ISDIGIT (*p); ++p)
    15501647    label_number = (10 * label_number) + *p - '0';
    15511648
     
    15571654    return s;
    15581655
    1559   for (instance_number = 0, p++; isdigit ((unsigned char) *p); ++p)
     1656  for (instance_number = 0, p++; ISDIGIT (*p); ++p)
    15601657    instance_number = (10 * instance_number) + *p - '0';
    15611658
     
    15751672#ifdef BFD_ASSEMBLER
    15761673  if (LOCAL_SYMBOL_CHECK (s))
    1577     return ((struct local_symbol *) s)->lsy_offset;
    1578 #endif
    1579 
    1580   if (!s->sy_resolved && s->sy_value.X_op != O_constant)
    1581     resolve_symbol_value (s, 1);
     1674    return resolve_symbol_value (s);
     1675#endif
     1676
     1677  if (!s->sy_resolved)
     1678    {
     1679      valueT val = resolve_symbol_value (s);
     1680      if (!finalize_syms)
     1681        return val;
     1682    }
    15821683  if (s->sy_value.X_op != O_constant)
    15831684    {
     
    15851686
    15861687      /* FIXME: In non BFD assemblers, S_IS_DEFINED and S_IS_COMMON
    1587         may call S_GET_VALUE.  We use a static symbol to avoid the
    1588         immediate recursion.  */
     1688        may call S_GET_VALUE.  We use a static symbol to avoid the
     1689        immediate recursion.  */
    15891690      if (recur == s)
    15901691        return (valueT) s->sy_value.X_add_number;
     
    15931694          || s->sy_value.X_op != O_symbol
    15941695          || (S_IS_DEFINED (s) && ! S_IS_COMMON (s)))
    1595         as_bad (_("Attempt to get value of unresolved symbol %s"),
     1696        as_bad (_("attempt to get value of unresolved symbol `%s'"),
    15961697                S_GET_NAME (s));
    15971698      recur = NULL;
     
    16101711  if (LOCAL_SYMBOL_CHECK (s))
    16111712    {
    1612       ((struct local_symbol *) s)->lsy_offset = val;
     1713      ((struct local_symbol *) s)->lsy_value = val;
    16131714      return;
    16141715    }
     
    17001801    return ((struct local_symbol *) s)->lsy_section != undefined_section;
    17011802  return s->bsym->section != undefined_section;
     1803}
     1804
     1805
     1806#ifndef EXTERN_FORCE_RELOC
     1807#define EXTERN_FORCE_RELOC IS_ELF
     1808#endif
     1809
     1810/* Return true for symbols that should not be reduced to section
     1811   symbols or eliminated from expressions, because they may be
     1812   overridden by the linker.  */
     1813int
     1814S_FORCE_RELOC (s, strict)
     1815     symbolS *s;
     1816     int strict;
     1817{
     1818  if (LOCAL_SYMBOL_CHECK (s))
     1819    return ((struct local_symbol *) s)->lsy_section == undefined_section;
     1820
     1821  return ((strict
     1822           && ((s->bsym->flags & BSF_WEAK) != 0
     1823               || (EXTERN_FORCE_RELOC
     1824                   && (s->bsym->flags & BSF_GLOBAL) != 0)))
     1825          || s->bsym->section == undefined_section
     1826          || bfd_is_com_section (s->bsym->section));
    17021827}
    17031828
     
    17631888}
    17641889
    1765 CONST char *
     1890const char *
    17661891S_GET_NAME (s)
    17671892     symbolS *s;
     
    18251950      char * file;
    18261951      unsigned int line;
    1827      
     1952
    18281953      /* Do not reassign section symbols.  */
    18291954      as_where (& file, & line);
    18301955      as_warn_where (file, line,
    1831                      _("Section symbols are already global"));
     1956                     _("section symbols are already global"));
    18321957      return;
    18331958    }
     
    18591984  s->bsym->flags |= BSF_WEAK;
    18601985  s->bsym->flags &= ~(BSF_GLOBAL | BSF_LOCAL);
     1986}
     1987
     1988void
     1989S_SET_THREAD_LOCAL (s)
     1990     symbolS *s;
     1991{
     1992  if (LOCAL_SYMBOL_CHECK (s))
     1993    s = local_symbol_convert ((struct local_symbol *) s);
     1994  if (bfd_is_com_section (s->bsym->section)
     1995      && (s->bsym->flags & BSF_THREAD_LOCAL) != 0)
     1996    return;
     1997  s->bsym->flags |= BSF_THREAD_LOCAL;
     1998  if ((s->bsym->flags & BSF_FUNCTION) != 0)
     1999    as_bad (_("Accessing function `%s' as thread-local object"),
     2000            S_GET_NAME (s));
     2001  else if (! bfd_is_und_section (s->bsym->section)
     2002           && (s->bsym->section->flags & SEC_THREAD_LOCAL) == 0)
     2003    as_bad (_("Accessing `%s' as thread-local object"),
     2004            S_GET_NAME (s));
    18612005}
    18622006
     
    21402284    return 0;
    21412285  return s->sy_value.X_op == O_symbol;
     2286}
     2287
     2288/* Return whether a symbol is equated to another symbol, and should be
     2289   treated specially when writing out relocs.  */
     2290
     2291int
     2292symbol_equated_reloc_p (s)
     2293     symbolS *s;
     2294{
     2295  if (LOCAL_SYMBOL_CHECK (s))
     2296    return 0;
     2297  /* X_op_symbol, normally not used for O_symbol, is set by
     2298     resolve_symbol_value to flag expression syms that have been
     2299     equated.  */
     2300  return (s->sy_value.X_op == O_symbol
     2301          && ((s->sy_resolved && s->sy_value.X_op_symbol != NULL)
     2302              || ! S_IS_DEFINED (s)
     2303              || S_IS_COMMON (s)));
    21422304}
    21432305
     
    23282490
    23292491      if (s != undefined_section
    2330           && s != expr_section)
     2492          && s != expr_section)
    23312493        fprintf (file, " %lx", (long) S_GET_VALUE (sym));
    23322494    }
     
    23392501      if (LOCAL_SYMBOL_CHECK (sym))
    23402502        fprintf (file, "constant %lx",
    2341                  (long) ((struct local_symbol *) sym)->lsy_offset);
     2503                 (long) ((struct local_symbol *) sym)->lsy_value);
    23422504      else
    23432505#endif
Note: See TracChangeset for help on using the changeset viewer.