]> oss.titaniummirror.com Git - msp430-binutils.git/blobdiff - bfd/coff-ppc.c
Imported binutils-2.20
[msp430-binutils.git] / bfd / coff-ppc.c
index 7e5f1264cce098f0134a315b682d41b507e6ac39..307b7c70648d79ef691f81034599fb98876d8e6c 100644 (file)
@@ -1,6 +1,6 @@
 /* BFD back-end for PowerPC Microsoft Portable Executable files.
    Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
+   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
    Free Software Foundation, Inc.
 
    Original version pieced together by Kim Knuttila (krk@cygnus.com)
@@ -982,6 +982,18 @@ static bfd_boolean in_reloc_p(abfd, howto)
       && (howto->type != IMAGE_REL_PPC_TOCREL16_DEFN) ;
 }
 
+static bfd_boolean
+write_base_file_entry (bfd *obfd, struct bfd_link_info *info, bfd_vma addr)
+{
+  if (coff_data (obfd)->pe)
+     addr -= pe_data (obfd)->pe_opthdr.ImageBase;
+  if (fwrite (&addr, sizeof (addr), 1, (FILE *) info->base_file) == 1)
+    return TRUE;
+
+  bfd_set_error (bfd_error_system_call);
+  return FALSE;
+}
+
 /* The reloc processing routine for the optimized COFF linker.  */
 
 static bfd_boolean
@@ -1237,10 +1249,8 @@ coff_ppc_relocate_section (output_bfd, info, input_bfd, input_section,
                bfd_vma addr = (toc_section->output_section->vma
                                + toc_section->output_offset + our_toc_offset);
 
-               if (coff_data (output_bfd)->pe)
-                 addr -= pe_data(output_bfd)->pe_opthdr.ImageBase;
-
-               fwrite (&addr, 1,4, (FILE *) info->base_file);
+               if (!write_base_file_entry (output_bfd, info, addr))
+                 return FALSE;
              }
 
            /* FIXME: this test is conservative.  */
@@ -1453,15 +1463,13 @@ coff_ppc_relocate_section (output_bfd, info, input_bfd, input_section,
              /* Relocation to a symbol in a section which
                 isn't absolute - we output the address here
                 to a file.  */
-             bfd_vma addr = rel->r_vaddr
-               - input_section->vma
-               + input_section->output_offset
-                 + input_section->output_section->vma;
+             bfd_vma addr = (rel->r_vaddr
+                             - input_section->vma
+                             + input_section->output_offset
+                             + input_section->output_section->vma);
 
-             if (coff_data (output_bfd)->pe)
-               addr -= pe_data (output_bfd)->pe_opthdr.ImageBase;
-
-             fwrite (&addr, 1,4, (FILE *) info->base_file);
+             if (!write_base_file_entry (output_bfd, info, addr))
+               return FALSE;
            }
        }
 
@@ -1535,9 +1543,9 @@ dump_toc (vfile)
   FILE *file = (FILE *) vfile;
   struct list_ele *t;
 
-  fprintf (file, _(h1));
-  fprintf (file, _(h2));
-  fprintf (file, _(h3));
+  fputs (_(h1), file);
+  fputs (_(h2), file);
+  fputs (_(h3), file);
 
   for (t = head; t != 0; t=t->next)
     {
@@ -1558,8 +1566,8 @@ dump_toc (vfile)
            {
              fprintf (file,
                      _("**** global_toc_size %ld(%lx), thunk_size %ld(%lx)\n"),
-                      global_toc_size, global_toc_size,
-                      thunk_size, thunk_size);
+                      global_toc_size, (unsigned long) global_toc_size,
+                      thunk_size, (unsigned long) thunk_size);
              cat = _("Out of bounds!");
            }
        }