old-cross-binutils/bfd/osf-core.c
David MacKenzie 9783e04a64 Make all callers of malloc or realloc (including via obstacks)
check the result for NULL.  Most set bfd_error to no_memory and
	return in that case; a few are harder to fix, and are marked
	with "FIXME <return type>".

	* elf32-hppa.c (hppa_elf_build_arg_reloc_stub
	hppa_elf_build_long_branch_stub):  Check bfd_make_empty_symbol return.
	* linker.c (_bfd_generic_link_output_symbols
	_bfd_generic_link_write_global_symbol): Ditto
	* section.c (bfd_make_section_anyway): Ditto.

	* tekhex.c (find_chunk tekhex_mkobject): Check bfd_alloc.
	(first_phase): Ditto.  FIXME void
	(tekhex_make_empty_symbol): Check bfd_zalloc.

	* sunos.c (sunos_read_dynamic_info): Check bfd_zalloc.
	(MY(read_dynamic_symbols) MY(read_dynamic_relocs)): Check bfd_alloc.

	* stringhash.c (_bfd_stringtab_hash_newfunc): Check bfd_hash_allocate.

	* srec.c: Indent.
	(fillup_symbols): Check bfd_alloc.  FIXME void
	(srec_mkobject srec_get_section_contents
	srec_set_section_contents): Check bfd_alloc.
	(srec_make_empty_symbol): Check bfd_zalloc.

	* som.c (hppa_som_gen_reloc_type): Check bfd_alloc_by_size_t.
	(make_unique_section): Check bfd_alloc.
	(som_new_section_hook): Check bfd_zalloc.
	(bfd_som_attach_aux_hdr): Ditto.  FIXME void

	* rs6000-core.c (rs6000coff_core_p): Check bfd_zalloc.

	* osf-core.c (osf_core_make_empty_symbol): Check bfd_zalloc.
	(osf_core_core_file_p): Check bfd_alloc.

	* oasys.c (oasys_slurp_symbol_table oasys_archive_p
	oasys_mkobject oasys_object_p oasys_new_section_hook
	oasys_set_section_contents): Check bfd_alloc.
	(oasys_slurp_section_data): Check bfd_zalloc and bfd_alloc.
	(oasys_make_empty_symbol): Check bfd_zalloc.

	* nlmcode.h (nlm_make_empty_symbol): Check bfd_zalloc.
	(nlm_slurp_symbol_table): Check bfd_zalloc and bfd_alloc.

	* nlm32-sparc.c (nlm_sparc_read_import): Check bfd_alloc.

	* nlm32-i386.c (nlm_i386_read_import): Check bfd_alloc.

	* nlm32-alpha.c (nlm_alpha_read_import): Check bfd_alloc.

	* linker.c (_bfd_link_hash_newfunc
	(generic_link_hash_newfunc
	(archive_hash_newfunc
	(_bfd_generic_link_add_one_symbol): Check bfd_hash_allocate.
	(_bfd_generic_final_link
	(_bfd_generic_link_output_symbols
	(default_indirect_link_order): Check bfd_alloc.
	(bfd_new_link_order): Check bfd_alloc_by_size_t.

	* irix-core.c (irix_core_make_empty_symbol): Check bfd_zalloc.

	* ieee.c: Indent.
	(read_id get_symbol get_section_entry ieee_archive_p ieee_object_p
	ieee_slurp_section_data ieee_new_section_hook): Check bfd_alloc.
	(do_one): Check bfd_alloc.  Return a boolean.
	(ieee_slurp_section_data): Check it.
	(init_for_output): Check bfd_alloc.  Return a boolean.
	(ieee_set_section_contents): Check it.
	(do_with_relocs):  Check bfd_alloc.  Return a boolean.
	(ieee_bfd_debug_info_accumulate): Ditto.  FIXME void.
	(ieee_mkobject): Check bfd_zalloc.
	(ieee_make_empty_symbol): Check bfd_zmalloc.

	* hpux-core.c (hpux_core_make_empty_symbol): Check
	bfd_zalloc.

	* hppabsd-core.c (hppabsd_core_make_empty_symbol): Check
	bfd_zalloc.
	(hppabsd_core_core_file_p): Check bfd_zalloc.

	* hp300hpux.c (MY(slurp_symbol_table)): Check bfd_alloc.

	* elfcode.h (elf_new_section_hook): Check bfd_alloc.
	(bfd_section_from_phdr): Ditto.
	(write_relocs): Ditto.  FIXME void
	(elf_map_symbols assign_section_numbers map_program_segments):
	Ditto.  Return a boolean.
	(swap_out_syms): Ditto.  Check elf_map_symbols.
	(elf_slurp_symbol_table): Check bfd_zalloc.
	(elf_slurp_reloca_table): Check bfd_alloc.
	(elf_slurp_reloc_table): Ditto.
	(elf_compute_section_file_positions): Check assign_section_numbers.
	(assign_file_positions_except_relocs): Return a boolean.
	Check map_program_segments.
	(elf_compute_section_file_positions): Check it.

	* elf32-mips.c (mips_elf_final_link): Check bfd_alloc.

	* elf32-hppa.c (hppa_elf_stub_branch_reloc): Check bfd_zmalloc and
	realloc.
	(hppa_elf_stub_reloc): Ditto.
	(hppa_elf_build_arg_reloc_stub): Check bfd_zalloc.
	(hppa_elf_build_long_branch_stub): Ditto.
	(elf32_hppa_backend_symbol_table_processing): Ditto.

	* ecoff.c (ecoff_set_symbol_info): Check bfd_alloc.  Return a boolean.
	(ecoff_slurp_symbol_table): Check it.
	(ecoff_slurp_armap): Check bfd_alloc.
	(ecoff_write_armap): Check bfd_zalloc.
	(ecoff_link_hash_newfunc): Check bfd_hash_allocate and
	_bfd_link_hash_newfunc.
	(ecoff_link_add_externals): Check bfd_alloc.

	* ctor.c (bfd_constructor_entry): Check bfd_alloc.

	* coffgen.c (coff_real_object_p): Check bfd_alloc.
	(coff_renumber_symbols): Check bfd_alloc_by_size_t.  Return a boolean.
	(coff_write_symbol): Check bfd_alloc.  FIXME int
	(coff_write_linenumbers): Check bfd_alloc.  Return a boolean.
	(coff_section_symbol): Check bfd_alloc_by_size_t.
	(coff_get_normalized_symtab): Check bfd_alloc.
	(coff_bfd_make_debug_symbol): Check bfd_zalloc.
	* libcoff-in.h: Change decls of coff_renumber_symbols,
	coff_write_linenumbers.
	* libcoff.h: Rebuilt.
	* coffcode.h (coff_write_object_contents): Check
	coff_renumber_symbols, coff_write_linenumbers.

	* coffcode.h: Indent.
	(coff_add_missing_symbols): Check bfd_alloc_by_size_t.  Return a
	boolean.
	(coff_write_object_contents): Check it.

	* coff-alpha.c (alpha_relocate_section): Check bfd_alloc.
	* coff-mips.c (mips_relocate_section): Ditto.

	* archive.c (bfd_slurp_bsd_armap_f2): Check bfd_alloc value.
	(do_slurp_bsd_armap): Ditto.
	(compute_and_write_armap): Check bfd_realloc value.

	* aoutx.h (translate_from_native_sym_flags): Check bfd_alloc
	return value.  Return boolean value.
	(NAME(aout,make_empty_symbol)): Check bfd_zalloc return value.
	(NAME(aout,slurp_symbol_table)): Check bf_alloc and bfd_zalloc
	return value.
	(add_to_stringtab): Ditto.  FIXME void
	(aout_link_hash_newfunc): Check bfd_hash_allocate return value.
	(aout_link_add_symbols): Check bfd_alloc value.
	(translate_symbol_table): Check translate_from_native_sym_flags.
	* hp300hpux.c (MY(slurp_symbol_table)): Ditto.
	* aoutx.h (aout_link_hash_newfunc): Check _bfd_link_hash_newfunc.

	* opncls.c (bfd_zalloc bfd_realloc): Check result of bfd_alloc.

	* opncls.c (obstack_chunk_alloc): Define as malloc, not
	bfd_xmalloc_by_size_t.
	(_bfd_new_bfd): Check obstack_begin for 0 return.

	* ieee.c (obstack_chunk_alloc): Define as malloc, not
	bfd_xmalloc_by_size_t.
	(ieee_archive_p): Check obstack_begin for 0 return and
	obstack_finish for NULL return.

	* hash.c (obstack_chunk_alloc): Define as malloc, not
	bfd_xmalloc_by_size_t.
	(bfd_hash_table_init_n): Check obstack_begin for 0 return and
	obstack_finish for NULL return.
	(bfd_hash_lookup): Check obstack_alloc for NULL return.

	* ecofflink.c (obstack_chunk_alloc): Define as malloc, not
	bfd_xmalloc_by_size_t.
	bfd_ecoff_debug_accumulate
	bfd_ecoff_debug_accumulate_other): Check obstack_alloc.
	(add_file_shuffle add_memory_shuffle): Check obstack_alloc for
	NULL return.  Return boolean, not void.
	(bfd_ecoff_debug_init): Check obstack_begin for 0 return.
	(bfd_ecoff_debug_accumulate): Check add_file_shuffle
	and add_memory_shuffle return.
	(string_hash_newfunc): Check bfd_hash_allocate and bfd_hash_newfunc.
	(bfd_ecoff_debug_accumulate): Check bfd_alloc.
	(ecoff_add_string): Check add_memory_shuffle return.

	* libbfd-in.h (xmalloc, bfd_xmalloc, bfd_xmalloc_by_size_t):
	Remove decls.
	* libbfd.h: Rebuilt.
1994-02-12 00:45:54 +00:00

305 lines
9.4 KiB
C
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* BFD back-end for OSF/1 core files.
Copyright 1993 Free Software Foundation, Inc.
This file is part of BFD, the Binary File Descriptor library.
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
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
/* This file can only be compiled on systems which use OSF/1 style
core files. In the config/XXXXXX.mh file for such a system add
HDEFINES=-DOSF_CORE
HDEPFILES=osf-core.o
*/
#include "bfd.h"
#include "sysdep.h"
#include "libbfd.h"
#include <stdio.h>
#include <string.h>
#include <sys/user.h>
#include <sys/core.h>
/* forward declarations */
static asection *
make_bfd_asection PARAMS ((bfd *, CONST char *, flagword, bfd_size_type,
bfd_vma, file_ptr));
static asymbol *
osf_core_make_empty_symbol PARAMS ((bfd *));
static bfd_target *
osf_core_core_file_p PARAMS ((bfd *));
static char *
osf_core_core_file_failing_command PARAMS ((bfd *));
static int
osf_core_core_file_failing_signal PARAMS ((bfd *));
static boolean
osf_core_core_file_matches_executable_p PARAMS ((bfd *, bfd *));
static void
swap_abort PARAMS ((void));
/* These are stored in the bfd's tdata */
struct osf_core_struct
{
int sig;
char cmd[MAXCOMLEN + 1];
};
#define core_hdr(bfd) ((bfd)->tdata.osf_core_data)
#define core_signal(bfd) (core_hdr(bfd)->sig)
#define core_command(bfd) (core_hdr(bfd)->cmd)
static asection *
make_bfd_asection (abfd, name, flags, _raw_size, vma, filepos)
bfd *abfd;
CONST char *name;
flagword flags;
bfd_size_type _raw_size;
bfd_vma vma;
file_ptr filepos;
{
asection *asect;
asect = bfd_make_section (abfd, name);
if (!asect)
return NULL;
asect->flags = flags;
asect->_raw_size = _raw_size;
asect->vma = vma;
asect->filepos = filepos;
asect->alignment_power = 8;
return asect;
}
static asymbol *
osf_core_make_empty_symbol (abfd)
bfd *abfd;
{
asymbol *new = (asymbol *) bfd_zalloc (abfd, sizeof (asymbol));
if (new)
new->the_bfd = abfd;
return new;
}
static bfd_target *
osf_core_core_file_p (abfd)
bfd *abfd;
{
int val;
int i;
char *secname;
struct core_filehdr core_header;
int dseccnt = 0;
val = bfd_read ((PTR)&core_header, 1, sizeof core_header, abfd);
if (val != sizeof core_header)
return NULL;
if (strncmp (core_header.magic, "Core", 4) != 0)
return NULL;
core_hdr (abfd) = (struct osf_core_struct *)
bfd_zalloc (abfd, sizeof (struct osf_core_struct));
if (!core_hdr (abfd))
return NULL;
strncpy (core_command (abfd), core_header.name, MAXCOMLEN + 1);
core_signal (abfd) = core_header.signo;
for (i = 0; i < core_header.nscns; i++)
{
struct core_scnhdr core_scnhdr;
val = bfd_read ((PTR)&core_scnhdr, 1, sizeof core_scnhdr, abfd);
if (val != sizeof core_scnhdr)
break;
/* Skip empty sections. */
if (core_scnhdr.size == 0 || core_scnhdr.scnptr == 0)
continue;
switch (core_scnhdr.scntype)
{
case SCNRGN:
/* OSF/1 has multiple data sections (data, bss and data/bss sections
for shared libraries), but bfd doesn't permit data sections with
the same name. Construct a unique section name. */
secname = bfd_alloc (abfd, 40);
if (!secname)
{
bfd_error = no_memory;
return NULL;
}
sprintf (secname, ".data%d", dseccnt++);
break;
case SCNSTACK:
secname = ".stack";
break;
case SCNREGS:
secname = ".reg";
break;
default:
fprintf (stderr, "Unhandled OSF/1 core file section type %d\n",
core_scnhdr.scntype);
continue;
}
if (!make_bfd_asection (abfd, secname,
SEC_ALLOC+SEC_LOAD+SEC_HAS_CONTENTS,
(bfd_size_type) core_scnhdr.size,
(bfd_vma) core_scnhdr.vaddr,
(file_ptr) core_scnhdr.scnptr))
return NULL;
}
/* OK, we believe you. You're a core file (sure, sure). */
return abfd->xvec;
}
static char *
osf_core_core_file_failing_command (abfd)
bfd *abfd;
{
return core_command (abfd);
}
/* ARGSUSED */
static int
osf_core_core_file_failing_signal (abfd)
bfd *abfd;
{
return core_signal (abfd);
}
/* ARGSUSED */
static boolean
osf_core_core_file_matches_executable_p (core_bfd, exec_bfd)
bfd *core_bfd, *exec_bfd;
{
return true; /* FIXME, We have no way of telling at this point */
}
/* No archive file support via this BFD */
#define osf_core_openr_next_archived_file bfd_generic_openr_next_archived_file
#define osf_core_generic_stat_arch_elt bfd_generic_stat_arch_elt
#define osf_core_slurp_armap bfd_false
#define osf_core_slurp_extended_name_table bfd_true
#define osf_core_write_armap (boolean (*) PARAMS \
((bfd *arch, unsigned int elength, struct orl *map, \
unsigned int orl_count, int stridx))) bfd_false
#define osf_core_truncate_arname bfd_dont_truncate_arname
#define osf_core_close_and_cleanup bfd_generic_close_and_cleanup
#define osf_core_set_section_contents (boolean (*) PARAMS \
((bfd *abfd, asection *section, PTR data, file_ptr offset, \
bfd_size_type count))) bfd_generic_set_section_contents
#define osf_core_get_section_contents bfd_generic_get_section_contents
#define osf_core_new_section_hook (boolean (*) PARAMS \
((bfd *, sec_ptr))) bfd_true
#define osf_core_get_symtab_upper_bound bfd_0u
#define osf_core_get_symtab (unsigned int (*) PARAMS \
((bfd *, struct symbol_cache_entry **))) bfd_0u
#define osf_core_get_reloc_upper_bound (unsigned int (*) PARAMS \
((bfd *, sec_ptr))) bfd_0u
#define osf_core_canonicalize_reloc (unsigned int (*) PARAMS \
((bfd *, sec_ptr, arelent **, struct symbol_cache_entry**))) bfd_0u
#define osf_core_print_symbol (void (*) PARAMS \
((bfd *, PTR, struct symbol_cache_entry *, \
bfd_print_symbol_type))) bfd_false
#define osf_core_get_symbol_info (void (*) PARAMS \
((bfd *, struct symbol_cache_entry *, \
symbol_info *))) bfd_false
#define osf_core_get_lineno (alent * (*) PARAMS \
((bfd *, struct symbol_cache_entry *))) bfd_nullvoidptr
#define osf_core_set_arch_mach (boolean (*) PARAMS \
((bfd *, enum bfd_architecture, unsigned long))) bfd_false
#define osf_core_find_nearest_line (boolean (*) PARAMS \
((bfd *abfd, struct sec *section, \
struct symbol_cache_entry **symbols,bfd_vma offset, \
CONST char **file, CONST char **func, unsigned int *line))) bfd_false
#define osf_core_sizeof_headers (int (*) PARAMS \
((bfd *, boolean))) bfd_0
#define osf_core_bfd_debug_info_start bfd_void
#define osf_core_bfd_debug_info_end bfd_void
#define osf_core_bfd_debug_info_accumulate (void (*) PARAMS \
((bfd *, struct sec *))) bfd_void
#define osf_core_bfd_get_relocated_section_contents bfd_generic_get_relocated_section_contents
#define osf_core_bfd_relax_section bfd_generic_relax_section
#define osf_core_bfd_reloc_type_lookup \
((CONST struct reloc_howto_struct *(*) PARAMS ((bfd *, bfd_reloc_code_real_type))) bfd_nullvoidptr)
#define osf_core_bfd_make_debug_symbol \
((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr)
#define osf_core_bfd_link_hash_table_create \
((struct bfd_link_hash_table *(*) PARAMS ((bfd *))) bfd_nullvoidptr)
#define osf_core_bfd_link_add_symbols \
((boolean (*) PARAMS ((bfd *, struct bfd_link_info *))) bfd_false)
#define osf_core_bfd_final_link \
((boolean (*) PARAMS ((bfd *, struct bfd_link_info *))) bfd_false)
/* If somebody calls any byte-swapping routines, shoot them. */
static void
swap_abort()
{
abort(); /* This way doesn't require any declaration for ANSI to fuck up */
}
#define NO_GET ((bfd_vma (*) PARAMS (( const bfd_byte *))) swap_abort )
#define NO_PUT ((void (*) PARAMS ((bfd_vma, bfd_byte *))) swap_abort )
#define NO_SIGNED_GET \
((bfd_signed_vma (*) PARAMS ((const bfd_byte *))) swap_abort )
bfd_target osf_core_vec =
{
"osf-core",
bfd_target_unknown_flavour,
true, /* target byte order */
true, /* target headers byte order */
(HAS_RELOC | EXEC_P | /* object flags */
HAS_LINENO | HAS_DEBUG |
HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
(SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
0, /* symbol prefix */
' ', /* ar_pad_char */
16, /* ar_max_namelen */
3, /* minimum alignment power */
NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit data */
NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit data */
NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit data */
NO_GET, NO_SIGNED_GET, NO_PUT, /* 64 bit hdrs */
NO_GET, NO_SIGNED_GET, NO_PUT, /* 32 bit hdrs */
NO_GET, NO_SIGNED_GET, NO_PUT, /* 16 bit hdrs */
{ /* bfd_check_format */
_bfd_dummy_target, /* unknown format */
_bfd_dummy_target, /* object file */
_bfd_dummy_target, /* archive */
osf_core_core_file_p /* a core file */
},
{ /* bfd_set_format */
bfd_false, bfd_false,
bfd_false, bfd_false
},
{ /* bfd_write_contents */
bfd_false, bfd_false,
bfd_false, bfd_false
},
JUMP_TABLE(osf_core),
(PTR) 0 /* backend_data */
};