* regcache.c (regcache_raw_read): If the target didn't supply a
[deliverable/binutils-gdb.git] / bfd / coff-ppc.c
index 611c9e051a6b11063d7addc29ab2e23afe12e4fa..69e10d8c6671a5b3c230d11e7ee345777b742075 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, 2010, 2011
    Free Software Foundation, Inc.
 
    Original version pieced together by Kim Knuttila (krk@cygnus.com)
@@ -13,7 +13,7 @@
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
@@ -33,9 +33,8 @@
    - dlltool will not produce correct output in some .reloc cases, and will
      not produce the right glue code for dll function calls.  */
 
-#include "bfd.h"
 #include "sysdep.h"
-
+#include "bfd.h"
 #include "libbfd.h"
 
 #include "coff/powerpc.h"
@@ -868,8 +867,6 @@ ppc_record_toc_entry(abfd, info, sec, sym, toc_kind)
      enum toc_type toc_kind ATTRIBUTE_UNUSED;
 {
   struct ppc_coff_link_hash_entry *h;
-  const char *name;
-
   int *local_syms;
 
   h = 0;
@@ -918,8 +915,6 @@ ppc_record_toc_entry(abfd, info, sec, sym, toc_kind)
     }
   else
     {
-      name = h->root.root.root.string;
-
       /* Check to see if there's a toc slot allocated. If not, do it
         here. It will be used in relocate_section.  */
       if (IS_UNALLOCATED(h->toc_offset))
@@ -983,6 +978,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
@@ -999,8 +1006,6 @@ coff_ppc_relocate_section (output_bfd, info, input_bfd, input_section,
 {
   struct internal_reloc *rel;
   struct internal_reloc *relend;
-  bfd_boolean hihalf;
-  bfd_vma hihalf_val;
   asection *toc_section = 0;
   bfd_vma relocation;
   reloc_howto_type *howto = 0;
@@ -1011,9 +1016,6 @@ coff_ppc_relocate_section (output_bfd, info, input_bfd, input_section,
   if (info->relocatable)
     return TRUE;
 
-  hihalf = FALSE;
-  hihalf_val = 0;
-
   rel = relocs;
   relend = rel + input_section->reloc_count;
   for (; rel < relend; rel++)
@@ -1238,10 +1240,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.  */
@@ -1266,17 +1266,12 @@ coff_ppc_relocate_section (output_bfd, info, input_bfd, input_section,
               appearing on the call instruction is a glue function or not.
               A glue function must announce itself via a IMGLUE reloc, and 
               the reloc contains the required toc restore instruction.  */
-           bfd_vma x;
-           const char *my_name;
-           
            DUMP_RELOC2 (howto->name, rel);
 
            if (h != 0)
              {
-               my_name = h->root.root.root.string;
                if (h->symbol_is_glue == 1)
                  {
-                   x = bfd_get_32 (input_bfd, loc);
                    bfd_put_32 (input_bfd, (bfd_vma) h->glue_insn, loc);
                  }
              }
@@ -1454,15 +1449,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;
            }
        }
 
@@ -1536,9 +1529,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)
     {
@@ -1559,8 +1552,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!");
            }
        }
@@ -1850,10 +1843,9 @@ ppc_coff_rtype2howto (relent, internal)
        howto = ppc_coff_howto_table + IMAGE_REL_PPC_TOCREL16;
       break;
     default:
-      fprintf (stderr,
-             _("Warning: Unsupported reloc %s [%d] used -- it may not work.\n"),
-             ppc_coff_howto_table[r_type].name,
-             r_type);
+      (*_bfd_error_handler) (_("warning: unsupported reloc %s [%d] used -- it may not work"),
+                            ppc_coff_howto_table[r_type].name,
+                            r_type);
       howto = ppc_coff_howto_table + r_type;
       break;
     }
@@ -1923,10 +1915,9 @@ coff_ppc_rtype_to_howto (abfd, sec, rel, h, sym, addendp)
       howto = ppc_coff_howto_table + r_type;
       break;
     default:
-      fprintf (stderr,
-             _("Warning: Unsupported reloc %s [%d] used -- it may not work.\n"),
-             ppc_coff_howto_table[r_type].name,
-             r_type);
+      (*_bfd_error_handler) (_("warning: unsupported reloc %s [%d] used -- it may not work"),
+                            ppc_coff_howto_table[r_type].name,
+                            r_type);
       howto = ppc_coff_howto_table + r_type;
       break;
     }
This page took 0.027501 seconds and 4 git commands to generate.