Fix tic54x testsuite failures and Lmem disassembly bugs.
[deliverable/binutils-gdb.git] / gas / write.c
index 4e1e06af01f8b5f6dac0c831e488cd4412c1cb08..70220155d3d67869dff7d89ff72ed366a75c2c5b 100644 (file)
@@ -769,8 +769,7 @@ adjust_reloc_syms (abfd, sec, xxx)
 
        /* If this symbol is equated to an undefined symbol, convert
            the fixup to being against that symbol.  */
-       if (sym != NULL && symbol_equated_p (sym)
-           && (! S_IS_DEFINED (sym) || S_IS_COMMON (sym)))
+       if (sym != NULL && symbol_equated_reloc_p (sym))
          {
            fixp->fx_offset += symbol_get_value_expression (sym)->X_add_number;
            sym = symbol_get_value_expression (sym)->X_add_symbol;
@@ -983,11 +982,10 @@ write_relocs (abfd, sec, xxx)
        }
 
       /* If this is an undefined symbol which was equated to another
-         symbol, then use generate the reloc against the latter symbol
+         symbol, then generate the reloc against the latter symbol
          rather than the former.  */
       sym = fixp->fx_addsy;
-      while (symbol_equated_p (sym)
-            && (! S_IS_DEFINED (sym) || S_IS_COMMON (sym)))
+      while (symbol_equated_reloc_p (sym))
        {
          symbolS *n;
 
@@ -1059,8 +1057,7 @@ write_relocs (abfd, sec, xxx)
          symbol, then generate the reloc against the latter symbol
          rather than the former.  */
       sym = fixp->fx_addsy;
-      while (symbol_equated_p (sym)
-            && (! S_IS_DEFINED (sym) || S_IS_COMMON (sym)))
+      while (symbol_equated_reloc_p (sym))
        sym = symbol_get_value_expression (sym)->X_add_symbol;
       fixp->fx_addsy = sym;
 
@@ -1234,7 +1231,7 @@ write_contents (abfd, sec, xxx)
                    (stdoutput, sec, buf, (file_ptr) offset,
                     (bfd_size_type) n_per_buf * fill_size);
                  if (x != true)
-                   as_fatal (_("Cannot write to output file."));
+                   as_fatal (_("cannot write to output file"));
                  offset += n_per_buf * fill_size;
                }
            }
@@ -1368,7 +1365,7 @@ set_symtab ()
   asymbol **asympp;
   symbolS *symp;
   boolean result;
-  extern PTR bfd_alloc PARAMS ((bfd *, size_t));
+  extern PTR bfd_alloc PARAMS ((bfd *, bfd_size_type));
 
   /* Count symbols.  We can't rely on a count made by the loop in
      write_object_file, because *_frob_file may add a new symbol or
@@ -1380,9 +1377,9 @@ set_symtab ()
   if (nsyms)
     {
       int i;
+      bfd_size_type amt = (bfd_size_type) nsyms * sizeof (asymbol *);
 
-      asympp = (asymbol **) bfd_alloc (stdoutput,
-                                      nsyms * sizeof (asymbol *));
+      asympp = (asymbol **) bfd_alloc (stdoutput, amt);
       symp = symbol_rootP;
       for (i = 0; i < nsyms; i++, symp = symbol_next (symp))
        {
@@ -1483,14 +1480,14 @@ write_object_file ()
     if (flag_always_generate_output)
       {
        if (n_warns || n_errs)
-         as_warn (_("%d error%s, %d warning%s, generating bad object file.\n"),
+         as_warn (_("%d error%s, %d warning%s, generating bad object file"),
                   n_errs, n_errs == 1 ? "" : "s",
                   n_warns, n_warns == 1 ? "" : "s");
       }
     else
       {
        if (n_errs)
-         as_fatal (_("%d error%s, %d warning%s, no object file generated.\n"),
+         as_fatal (_("%d error%s, %d warning%s, no object file generated"),
                    n_errs, n_errs == 1 ? "" : "s",
                    n_warns, n_warns == 1 ? "" : "s");
       }
@@ -1750,9 +1747,6 @@ write_object_file ()
            /* Patch the jump table.  */
            /* This is the offset from ??? to table_ptr+0.  */
            to_addr = table_addr - S_GET_VALUE (lie->sub);
-#ifdef BFD_ASSEMBLER
-           to_addr -= symbol_get_frag (lie->sub)->fr_address;
-#endif
 #ifdef TC_CHECK_ADJUSTED_BROKEN_DOT_WORD
            TC_CHECK_ADJUSTED_BROKEN_DOT_WORD (to_addr, lie);
 #endif
@@ -1769,9 +1763,6 @@ write_object_file ()
            /* This is a long jump from table_ptr+0 to the final target.  */
            from_addr = table_addr;
            to_addr = S_GET_VALUE (lie->add) + lie->addnum;
-#ifdef BFD_ASSEMBLER
-           to_addr += symbol_get_frag (lie->add)->fr_address;
-#endif
            md_create_long_jump (table_ptr, from_addr, to_addr, lie->dispfrag,
                                 lie->add);
            table_ptr += md_long_jump_size;
@@ -1889,8 +1880,8 @@ write_object_file ()
       obj_emit_strings (&next_object_file_charP);
 
 #ifdef BFD_HEADERS
-    bfd_seek (stdoutput, 0, 0);
-    bfd_write (the_object_file, 1, object_file_size, stdoutput);
+    bfd_seek (stdoutput, (file_ptr) 0, 0);
+    bfd_bwrite (the_object_file, (bfd_size_type) object_file_size, stdoutput);
 #else
 
     /* Write the data to the file.  */
@@ -1956,7 +1947,7 @@ write_object_file ()
              /* They only differ if `name' is a fb or dollar local
                 label name.  */
              if (name2 != name && ! S_IS_DEFINED (symp))
-               as_bad (_("local label %s is not defined"), name2);
+               as_bad (_("local label `%s' is not defined"), name2);
            }
 
          /* Do it again, because adjust_reloc_syms might introduce
@@ -1966,8 +1957,7 @@ write_object_file ()
 
          /* Skip symbols which were equated to undefined or common
              symbols.  */
-         if (symbol_equated_p (symp)
-             && (! S_IS_DEFINED (symp) || S_IS_COMMON (symp)))
+         if (symbol_equated_reloc_p (symp))
            {
              symbol_remove (symp, &symbol_rootP, &symbol_lastP);
              continue;
@@ -2019,7 +2009,7 @@ write_object_file ()
          /* Make sure we really got a value for the symbol.  */
          if (! symbol_resolved_p (symp))
            {
-             as_bad (_("can't resolve value for symbol \"%s\""),
+             as_bad (_("can't resolve value for symbol `%s'"),
                      S_GET_NAME (symp));
              symbol_mark_resolved (symp);
            }
@@ -2115,7 +2105,7 @@ relax_frag (segment, fragP, stretch)
 #endif
       know (!(S_GET_SEGMENT (symbolP) == absolute_section)
            || sym_frag == &zero_address_frag);
-      target += S_GET_VALUE (symbolP) + sym_frag->fr_address;
+      target += S_GET_VALUE (symbolP);
 
       /* If frag has yet to be reached on this pass,
         assume it will move by STRETCH just as we did.
@@ -2270,6 +2260,12 @@ relax_segment (segment_frag_root, segment)
          break;
 
        case rs_machine_dependent:
+         /* If fr_symbol is an expression, this call to
+            resolve_symbol_value sets up the correct segment, which will
+            likely be needed in md_estimate_size_before_relax.  */
+         if (fragP->fr_symbol)
+           resolve_symbol_value (fragP->fr_symbol);
+
          address += md_estimate_size_before_relax (fragP, segment);
          break;
 
@@ -2356,11 +2352,9 @@ relax_segment (segment_frag_root, segment)
                      if (lie->added)
                        continue;
 
-                     offset = (symbol_get_frag (lie->add)->fr_address
-                               + S_GET_VALUE (lie->add)
+                     offset = (S_GET_VALUE (lie->add)
                                + lie->addnum
-                               - (symbol_get_frag (lie->sub)->fr_address
-                                  + S_GET_VALUE (lie->sub)));
+                               - S_GET_VALUE (lie->sub));
                      if (offset <= -32768 || offset >= 32767)
                        {
                          if (flag_warn_displacement)
@@ -2436,9 +2430,13 @@ relax_segment (segment_frag_root, segment)
                      know (!(S_GET_SEGMENT (symbolP) == SEG_ABSOLUTE)
                            || (symbolP->sy_frag == &zero_address_frag));
 #endif
-                     target += (S_GET_VALUE (symbolP)
-                                + symbol_get_frag (symbolP)->fr_address);
-                   }           /* if we have a symbol  */
+                      /* Convert from an actual address to an octet offset
+                         into the section.  Here it is assumed that the
+                         section's VMA is zero, and can omit subtracting it
+                         from the symbol's value to get the address offset.  */
+                      know (S_GET_SECTION (symbolP)->vma == 0);
+                     target += S_GET_VALUE (symbolP) * OCTETS_PER_BYTE;
+                   }
 
                  know (fragP->fr_next);
                  after = fragP->fr_next->fr_address;
@@ -2449,7 +2447,7 @@ relax_segment (segment_frag_root, segment)
                         cannot have fewer than 0 chars.  That is, we can't
                         .org backwards.  */
                      as_bad_where (fragP->fr_file, fragP->fr_line,
-                                   _("attempt to .org backwards ignored"));
+                                   _("attempt to .org backwards"));
 
                      /* We've issued an error message.  Change the
                          frag to avoid cascading errors.  */
@@ -2488,7 +2486,7 @@ relax_segment (segment_frag_root, segment)
                        fragP->fr_symbol = 0;
                      }
                    else
-                     growth = (was_address + amount
+                     growth = (was_address + fragP->fr_fix + amount
                                - fragP->fr_next->fr_address);
                  }
                break;
@@ -2658,7 +2656,7 @@ fixup_segment (fixP, this_segment_type)
              else
              bad_sub_reloc:
                as_bad_where (fixP->fx_file, fixP->fx_line,
-                             _("Negative of non-absolute symbol %s"),
+                             _("negative of non-absolute symbol `%s'"),
                              S_GET_NAME (sub_symbolP));
            }
          else if (S_GET_SEGMENT (sub_symbolP) == add_symbol_segment
@@ -2672,7 +2670,7 @@ fixup_segment (fixP, this_segment_type)
                 as the target of a call instruction.  */
              if (fixP->fx_tcbit)
                as_bad_where (fixP->fx_file, fixP->fx_line,
-                             _("callj to difference of 2 symbols"));
+                             _("callj to difference of two symbols"));
 #endif /* TC_I960  */
              add_number += (S_GET_VALUE (add_symbolP)
                             - S_GET_VALUE (sub_symbolP));
@@ -2752,7 +2750,7 @@ fixup_segment (fixP, this_segment_type)
                  char buf[50];
                  sprint_value (buf, fragP->fr_address + where);
                  as_bad_where (fixP->fx_file, fixP->fx_line,
-                               _("Subtraction of two symbols in different sections \"%s\" {%s section} - \"%s\" {%s section} at file address %s."),
+                               _("subtraction of two symbols in different sections `%s' {%s section} - `%s' {%s section} at file address %s"),
                                S_GET_NAME (add_symbolP),
                                segment_name (S_GET_SEGMENT (add_symbolP)),
                                S_GET_NAME (sub_symbolP),
@@ -2817,6 +2815,9 @@ fixup_segment (fixP, this_segment_type)
              else if (add_symbol_segment == undefined_section
 #ifdef BFD_ASSEMBLER
                       || bfd_is_com_section (add_symbol_segment)
+                      || (bfd_get_section_flags (stdoutput,
+                                                 add_symbol_segment)
+                          & SEC_MERGE) != 0
 #endif
                       )
                {
@@ -2906,7 +2907,7 @@ fixup_segment (fixP, this_segment_type)
                  else
                    sprintf (buf2, "%ld", (long) add_number);
                  as_bad_where (fixP->fx_file, fixP->fx_line,
-                               _("Value of %s too large for field of %d bytes at %s"),
+                               _("value of %s too large for field of %d bytes at %s"),
                                buf2, size, buf);
                } /* Generic error checking.  */
            }
@@ -2918,7 +2919,7 @@ fixup_segment (fixP, this_segment_type)
              && size == 2
              && add_number > 0x7fff)
            as_bad_where (fixP->fx_file, fixP->fx_line,
-                         _("Signed .word overflow; switch may be too large; %ld at 0x%lx"),
+                         _("signed .word overflow; switch may be too large; %ld at 0x%lx"),
                          (long) add_number,
                          (unsigned long) (fragP->fr_address + where));
 #endif
This page took 0.034386 seconds and 4 git commands to generate.