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-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
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;
}
\f
#ifndef ARM_WINCE
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);
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
{
}
}
- 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;
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 *));
\f
/* The NT loader points the toc register to &toc + 32768, in order to
\f
/* 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
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;
}
\f
static bfd_reloc_status_type
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)
{
&& (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
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. */
/* 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;
}
}
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);
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);
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;
}