aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bfd/ChangeLog11
-rw-r--r--bfd/coff-arm.c45
-rw-r--r--bfd/coff-mcore.c32
-rw-r--r--bfd/coff-ppc.c32
-rw-r--r--bfd/elf32-arm.c14
-rw-r--r--bfd/vms-misc.c15
6 files changed, 91 insertions, 58 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index fba19d2..a93c102 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,14 @@
+2007-10-15 Alan Modra <amodra@bigpond.net.au>
+
+ * coff-arm.c (arm_emit_base_file_entry): Check fwrite return value.
+ Return status. Adjust callers.
+ * coff-mcore.c (mcore_emit_base_file_entry): Likewise.
+ * coff-ppc.c (write_base_file_entry): New function.
+ (coff_ppc_relocate_section): Use it.
+ * elf32-arm.c (find_thumb_glue): Check asprintf return status.
+ (find_arm_glue): Likewise.
+ * vms-misc.c (_bfd_vms_output_flush): Check fwrite return value.
+
2007-10-12 Nick Clifton <nickc@redhat.com>
PR 5160
diff --git a/bfd/coff-arm.c b/bfd/coff-arm.c
index b9f8c36..3bf61e5 100644
--- a/bfd/coff-arm.c
+++ b/bfd/coff-arm.c
@@ -939,21 +939,24 @@ coff_arm_link_hash_table_create (bfd * abfd)
return & ret->root.root;
}
-static void
+static bfd_boolean
arm_emit_base_file_entry (struct bfd_link_info *info,
bfd *output_bfd,
asection *input_section,
bfd_vma reloc_offset)
{
- bfd_vma addr = reloc_offset
- - input_section->vma
- + input_section->output_offset
- + input_section->output_section->vma;
+ bfd_vma addr = (reloc_offset
+ - 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, sizeof (addr), (FILE *) info->base_file);
+ if (fwrite (&addr, sizeof (addr), 1, (FILE *) info->base_file) == 1)
+ return TRUE;
+ bfd_set_error (bfd_error_system_call);
+ return FALSE;
}
#ifndef ARM_WINCE
@@ -1381,10 +1384,10 @@ coff_arm_relocate_section (bfd *output_bfd,
bfd_put_32 (output_bfd, h_val | a2t3_func_addr_insn,
s->contents + my_offset + 8);
- if (info->base_file)
- arm_emit_base_file_entry (info, output_bfd, s,
- my_offset + 8);
-
+ if (info->base_file
+ && !arm_emit_base_file_entry (info, output_bfd,
+ s, my_offset + 8))
+ return FALSE;
}
BFD_ASSERT (my_offset <= globals->arm_glue_size);
@@ -1486,9 +1489,11 @@ coff_arm_relocate_section (bfd *output_bfd,
bfd_put_32 (output_bfd, h_val,
s->contents + my_offset + 16);
- if (info->base_file)
- arm_emit_base_file_entry (info, output_bfd, s,
- my_offset + 16);
+ if (info->base_file
+ && !arm_emit_base_file_entry (info,
+ output_bfd, s,
+ my_offset + 16))
+ return FALSE;
}
else
{
@@ -1572,13 +1577,13 @@ coff_arm_relocate_section (bfd *output_bfd,
}
}
- if (info->base_file)
- {
- /* Emit a reloc if the backend thinks it needs it. */
- if (sym && pe_data(output_bfd)->in_reloc_p(output_bfd, howto))
- arm_emit_base_file_entry (info, output_bfd, input_section,
- rel->r_vaddr);
- }
+ /* Emit a reloc if the backend thinks it needs it. */
+ if (info->base_file
+ && sym
+ && pe_data(output_bfd)->in_reloc_p(output_bfd, howto)
+ && !arm_emit_base_file_entry (info, output_bfd, input_section,
+ rel->r_vaddr))
+ return FALSE;
if (done)
rstat = bfd_reloc_ok;
diff --git a/bfd/coff-mcore.c b/bfd/coff-mcore.c
index 861e19a..1d61748 100644
--- a/bfd/coff-mcore.c
+++ b/bfd/coff-mcore.c
@@ -51,8 +51,6 @@ static reloc_howto_type *coff_mcore_rtype_to_howto
PARAMS ((bfd *, asection *, struct internal_reloc *,
struct coff_link_hash_entry *, struct internal_syment *,
bfd_vma *));
-static void mcore_emit_base_file_entry
- PARAMS ((struct bfd_link_info *, bfd *, asection *, bfd_vma));
static bfd_boolean in_reloc_p PARAMS ((bfd *, reloc_howto_type *));
/* The NT loader points the toc register to &toc + 32768, in order to
@@ -221,12 +219,11 @@ mcore_hash_table;
/* Add an entry to the base file. */
-static void
-mcore_emit_base_file_entry (info, output_bfd, input_section, reloc_offset)
- struct bfd_link_info * info;
- bfd * output_bfd;
- asection * input_section;
- bfd_vma reloc_offset;
+static bfd_boolean
+mcore_emit_base_file_entry (struct bfd_link_info *info,
+ bfd *output_bfd,
+ asection *input_section,
+ bfd_vma reloc_offset)
{
bfd_vma addr = reloc_offset
- input_section->vma
@@ -236,7 +233,11 @@ mcore_emit_base_file_entry (info, output_bfd, input_section, reloc_offset)
if (coff_data (output_bfd)->pe)
addr -= pe_data (output_bfd)->pe_opthdr.ImageBase;
- fwrite (&addr, 1, sizeof (addr), (FILE *) info->base_file);
+ if (fwrite (&addr, sizeof (addr), 1, (FILE *) info->base_file) == 1)
+ return TRUE;
+
+ bfd_set_error (bfd_error_system_call);
+ return FALSE;
}
static bfd_reloc_status_type
@@ -522,12 +523,13 @@ coff_mcore_relocate_section (output_bfd, info, input_bfd, input_section,
break;
}
- if (info->base_file)
- {
- /* Emit a reloc if the backend thinks it needs it. */
- if (sym && pe_data (output_bfd)->in_reloc_p (output_bfd, howto))
- mcore_emit_base_file_entry (info, output_bfd, input_section, rel->r_vaddr);
- }
+ /* Emit a reloc if the backend thinks it needs it. */
+ if (info->base_file
+ && sym
+ && pe_data (output_bfd)->in_reloc_p (output_bfd, howto)
+ && !mcore_emit_base_file_entry (info, output_bfd, input_section,
+ rel->r_vaddr))
+ return FALSE;
switch (rstat)
{
diff --git a/bfd/coff-ppc.c b/bfd/coff-ppc.c
index 7e5f126..6f903e8 100644
--- a/bfd/coff-ppc.c
+++ b/bfd/coff-ppc.c
@@ -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;
}
}
diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c
index 5b536f8..cbde697 100644
--- a/bfd/elf32-arm.c
+++ b/bfd/elf32-arm.c
@@ -2520,9 +2520,10 @@ find_thumb_glue (struct bfd_link_info *link_info,
hash = elf_link_hash_lookup
(&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
- if (hash == NULL)
- asprintf (error_message, _("unable to find THUMB glue '%s' for '%s'"),
- tmp_name, name);
+ if (hash == NULL
+ && asprintf (error_message, _("unable to find THUMB glue '%s' for '%s'"),
+ tmp_name, name) == -1)
+ *error_message = (char *) bfd_errmsg (bfd_error_system_call);
free (tmp_name);
@@ -2553,9 +2554,10 @@ find_arm_glue (struct bfd_link_info *link_info,
myh = elf_link_hash_lookup
(&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
- if (myh == NULL)
- asprintf (error_message, _("unable to find ARM glue '%s' for '%s'"),
- tmp_name, name);
+ if (myh == NULL
+ && asprintf (error_message, _("unable to find ARM glue '%s' for '%s'"),
+ tmp_name, name) == -1)
+ *error_message = (char *) bfd_errmsg (bfd_error_system_call);
free (tmp_name);
diff --git a/bfd/vms-misc.c b/bfd/vms-misc.c
index 1492f14..98fbb0e 100644
--- a/bfd/vms-misc.c
+++ b/bfd/vms-misc.c
@@ -691,12 +691,17 @@ _bfd_vms_output_flush (bfd * abfd)
if (PRIV (push_level) == 0)
{
+ if (0
#ifndef VMS
- /* Write length first, see FF_FOREIGN in the input routines. */
- fwrite (PRIV (output_buf) + 2, 2, 1, (FILE *) abfd->iostream);
-#endif
- fwrite (PRIV (output_buf), (size_t) real_size, 1,
- (FILE *) abfd->iostream);
+ /* Write length first, see FF_FOREIGN in the input routines. */
+ || fwrite (PRIV (output_buf) + 2, 2, 1,
+ (FILE *) abfd->iostream) != 1
+#endif
+ || (real_size != 0
+ && fwrite (PRIV (output_buf), (size_t) real_size, 1,
+ (FILE *) abfd->iostream) != 1))
+ /* FIXME: Return error status. */
+ abort ();
PRIV (output_size) = 0;
}