(bfd_section_list_clear): New function.
(bfd_section_list_remove, bfd_section_list_insert): New macros.
(_bfd_strip_section_from_output): Use them.
* coffcode.h (coff_set_alignment_hook): Likewise.
* elf32-mips.c (_bfd_mips_elf_final_link): Likewise.
* elf64-mips.c (mips_elf64_final_link): Likewise.
* elf64-mmix.c (mmix_elf_final_link): Likewise.
* sunos.c (sunos_add_dynamic_symbols): Likewise.
* xcofflink.c (_bfd_xcoff_bfd_final_link): Likewise.
* bfd-in2.h: Regenerate.
* netbsd-core.c (netbsd_core_file_p): Use bfd_make_section_anyway
rather than doing our own section handling. Clean up after errors
with bfd_release and bfd_section_list_clear. Handle unexpected
flags.
* aoutf1.h (sunos4_core_file_p): Likewise.
* aix386-core.c (aix386_core_file_p): Likewise.
* cisco-core.c (cisco_core_file_validate): Likewise.
* ptrace-core.c (ptrace_unix_core_file_p): Likewise.
* trad-core.c (trad_unix_core_file_p): Likewise.
* hppabsd-core.c (hppabsd_core_core_file_p): Clean up after errors
with bfd_release and bfd_section_list_clear.
* hpux-core.c (hpux_core_core_file_p): Likewise.
* irix-core.c (irix_core_core_file_p): Likewise.
* lynx-core.c (lynx_core_file_p): Likewise.
* osf-core.c (osf_core_core_file_p): Likewise.
* rs6000-core.c (rs6000coff_core_p): Likewise.
* sco5-core.c (sco5_core_file_p): Likewise.
2002-01-05 Alan Modra <amodra@bigpond.net.au>
+ * section.c (bfd_section_init): Remove unnecessary initialisations.
+ (bfd_section_list_clear): New function.
+ (bfd_section_list_remove, bfd_section_list_insert): New macros.
+ (_bfd_strip_section_from_output): Use them.
+ * coffcode.h (coff_set_alignment_hook): Likewise.
+ * elf32-mips.c (_bfd_mips_elf_final_link): Likewise.
+ * elf64-mips.c (mips_elf64_final_link): Likewise.
+ * elf64-mmix.c (mmix_elf_final_link): Likewise.
+ * sunos.c (sunos_add_dynamic_symbols): Likewise.
+ * xcofflink.c (_bfd_xcoff_bfd_final_link): Likewise.
+ * bfd-in2.h: Regenerate.
+
+ * netbsd-core.c (netbsd_core_file_p): Use bfd_make_section_anyway
+ rather than doing our own section handling. Clean up after errors
+ with bfd_release and bfd_section_list_clear. Handle unexpected
+ flags.
+ * aoutf1.h (sunos4_core_file_p): Likewise.
+ * aix386-core.c (aix386_core_file_p): Likewise.
+ * cisco-core.c (cisco_core_file_validate): Likewise.
+ * ptrace-core.c (ptrace_unix_core_file_p): Likewise.
+ * trad-core.c (trad_unix_core_file_p): Likewise.
+
+ * hppabsd-core.c (hppabsd_core_core_file_p): Clean up after errors
+ with bfd_release and bfd_section_list_clear.
+ * hpux-core.c (hpux_core_core_file_p): Likewise.
+ * irix-core.c (irix_core_core_file_p): Likewise.
+ * lynx-core.c (lynx_core_file_p): Likewise.
+ * osf-core.c (osf_core_core_file_p): Likewise.
+ * rs6000-core.c (rs6000coff_core_p): Likewise.
+ * sco5-core.c (sco5_core_file_p): Likewise.
+
* elf32-mips.c (_bfd_mips_elf_lo16_reloc): Simplify, and perform
sign extension adjustments without conditionals.
This was based on trad-core.c, which was written by John Gilmore of
Cygnus Support.
Copyright 1988, 1989, 1991, 1992, 1993, 1994, 1996, 1998, 1999, 2000,
- 2001
+ 2001, 2002
Free Software Foundation, Inc.
Written by Minh Tran-Le <TRANLE@INTELLICORP.COM>.
Converted to back end form by Ian Lance Taylor <ian@cygnus.com>.
bfd_set_error (bfd_error_wrong_format);
loser:
bfd_release (abfd, (char *) mergem);
+ abfd->tdata.any = NULL;
+ bfd_section_list_clear (abfd);
return 0;
}
set_tdata (abfd, &mergem->coredata);
core_hdr (abfd) = core;
- /* Create the sections. This is raunchy, but bfd_close wants to
- reclaim them. */
- amt = sizeof (asection);
- core_regsec (abfd) = (asection *) bfd_zalloc (abfd, amt);
+ /* Create the sections. */
+ core_regsec (abfd) = bfd_make_section_anyway (abfd, ".reg");
if (core_regsec (abfd) == NULL)
goto loser;
- core_reg2sec (abfd) = (asection *) bfd_zalloc (abfd, amt);
+ core_regsec (abfd)->flags = SEC_HAS_CONTENTS;
+ core_regsec (abfd)->_raw_size = sizeof (core->cd_regs);
+ core_regsec (abfd)->vma = (bfd_vma) -1;
+
+ /* We'll access the regs afresh in the core file, like any section. */
+ core_regsec (abfd)->filepos =
+ (file_ptr) offsetof (struct corehdr, cd_regs[0]);
+
+ core_reg2sec (abfd) = bfd_make_section_anyway (abfd, ".reg2");
if (core_reg2sec (abfd) == NULL)
/* bfd_release frees everything allocated after it's arg. */
goto loser;
+ core_reg2sec (abfd)->flags = SEC_HAS_CONTENTS;
+ core_reg2sec (abfd)->_raw_size = sizeof (core->cd_fpregs);
+ core_reg2sec (abfd)->vma = (bfd_vma) -1;
+ core_reg2sec (abfd)->filepos =
+ (file_ptr) offsetof (struct corehdr, cd_fpregs);
+
for (i = 0, n = 0; (i < MAX_CORE_SEGS) && (core->cd_segs[i].cs_type); i++)
{
+ const char *sname;
+ flagword flags;
+
if (core->cd_segs[i].cs_offset == 0)
continue;
- core_section (abfd, n) = (asection *) bfd_zalloc (abfd, amt);
- if (core_section (abfd, n) == NULL)
- goto loser;
switch (core->cd_segs[i].cs_type)
{
case COR_TYPE_DATA:
- core_section (abfd, n)->name = ".data";
- core_section (abfd, n)->flags = (SEC_ALLOC + SEC_LOAD +
- SEC_HAS_CONTENTS);
+ sname = ".data";
+ flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
break;
case COR_TYPE_STACK:
- core_section (abfd, n)->name = ".stack";
- core_section (abfd, n)->flags = (SEC_ALLOC + SEC_LOAD +
- SEC_HAS_CONTENTS);
+ sname = ".stack";
+ flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
break;
case COR_TYPE_LIBDATA:
- core_section (abfd, n)->name = ".libdata";
- core_section (abfd, n)->flags = (SEC_ALLOC + SEC_HAS_CONTENTS);
+ sname = ".libdata";
+ flags = SEC_ALLOC + SEC_HAS_CONTENTS;
break;
case COR_TYPE_WRITE:
- core_section (abfd, n)->name = ".writeable";
- core_section (abfd, n)->flags = (SEC_ALLOC + SEC_HAS_CONTENTS);
+ sname = ".writeable";
+ flags = SEC_ALLOC + SEC_HAS_CONTENTS;
break;
case COR_TYPE_MSC:
- core_section (abfd, n)->name = ".misc";
- core_section (abfd, n)->flags = (SEC_ALLOC + SEC_HAS_CONTENTS);
+ sname = ".misc";
+ flags = SEC_ALLOC + SEC_HAS_CONTENTS;
break;
default:
- core_section (abfd, n)->name = ".unknown";
- core_section (abfd, n)->flags = (SEC_ALLOC + SEC_HAS_CONTENTS);
+ sname = ".unknown";
+ flags = SEC_ALLOC + SEC_HAS_CONTENTS;
break;
}
+ core_section (abfd, n) = bfd_make_section_anyway (abfd, sname);
+ if (core_section (abfd, n) == NULL)
+ goto loser;
+
+ core_section (abfd, n)->flags = flags;
core_section (abfd, n)->_raw_size = core->cd_segs[i].cs_len;
core_section (abfd, n)->vma = core->cd_segs[i].cs_address;
core_section (abfd, n)->filepos = core->cd_segs[i].cs_offset;
core_section (abfd, n)->alignment_power = 2;
- core_section (abfd, n)->next = NULL;
- if (n > 0)
- core_section (abfd, (n - 1))->next = core_section (abfd, n);
-
- abfd->section_count = ++n;
+ n++;
}
- core_regsec (abfd)->name = ".reg";
- core_reg2sec (abfd)->name = ".reg2";
-
- core_regsec (abfd)->flags = SEC_HAS_CONTENTS;
- core_reg2sec (abfd)->flags = SEC_HAS_CONTENTS;
-
- core_regsec (abfd)->_raw_size = sizeof (core->cd_regs);
- core_reg2sec (abfd)->_raw_size = sizeof (core->cd_fpregs);
-
- core_regsec (abfd)->vma = (bfd_vma) -1;
- core_reg2sec (abfd)->vma = (bfd_vma) -1;
-
- /* We'll access the regs afresh in the core file, like any section. */
- core_regsec (abfd)->filepos =
- (file_ptr) offsetof (struct corehdr, cd_regs[0]);
- core_reg2sec (abfd)->filepos =
- (file_ptr) offsetof (struct corehdr, cd_fpregs);
-
- /* Add the 2 reg fake sections to abfd. */
- abfd->section_count += 2;
- abfd->sections = core_regsec (abfd);
- core_regsec (abfd)->next = core_reg2sec (abfd);
- core_reg2sec (abfd)->next = core_section (abfd, 0);
-
return abfd->xvec;
}
/* A.out "format 1" file handling code for BFD.
Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000,
- 2001
+ 2001, 2002
Free Software Foundation, Inc.
Written by Cygnus Support.
{
loser:
bfd_release (abfd, (char *) mergem);
+ abfd->tdata.any = NULL;
+ bfd_section_list_clear (abfd);
return 0;
}
abfd->tdata.sun_core_data = &mergem->suncoredata;
abfd->tdata.sun_core_data->hdr = core;
- /* create the sections. This is raunchy, but bfd_close wants to reclaim
- them */
- amt = sizeof (asection);
- core_stacksec (abfd) = (asection *) bfd_zalloc (abfd, amt);
+ /* Create the sections. */
+ core_stacksec (abfd) = bfd_make_section_anyway (abfd, ".stack");
if (core_stacksec (abfd) == NULL)
/* bfd_release frees everything allocated after it's arg. */
goto loser;
- core_datasec (abfd) = (asection *) bfd_zalloc (abfd, amt);
+ core_datasec (abfd) = bfd_make_section_anyway (abfd, ".data");
if (core_datasec (abfd) == NULL)
goto loser;
- core_regsec (abfd) = (asection *) bfd_zalloc (abfd, amt);
+ core_regsec (abfd) = bfd_make_section_anyway (abfd, ".reg");
if (core_regsec (abfd) == NULL)
goto loser;
- core_reg2sec (abfd) = (asection *) bfd_zalloc (abfd, amt);
+ core_reg2sec (abfd) = bfd_make_section_anyway (abfd, ".reg2");
if (core_reg2sec (abfd) == NULL)
goto loser;
- core_stacksec (abfd)->name = ".stack";
- core_datasec (abfd)->name = ".data";
- core_regsec (abfd)->name = ".reg";
- core_reg2sec (abfd)->name = ".reg2";
-
core_stacksec (abfd)->flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
core_datasec (abfd)->flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
core_regsec (abfd)->flags = SEC_HAS_CONTENTS;
core_regsec (abfd)->alignment_power = 2;
core_reg2sec (abfd)->alignment_power = 2;
- abfd->sections = core_stacksec (abfd);
- core_stacksec (abfd)->next = core_datasec (abfd);
- core_datasec (abfd)->next = core_regsec (abfd);
- core_regsec (abfd)->next = core_reg2sec (abfd);
-
- abfd->section_count = 4;
-
return abfd->xvec;
}
#define bfd_get_section_size_after_reloc(section) \
((section)->reloc_done ? (section)->_cooked_size \
: (abort (), (bfd_size_type) 1))
+
+/* Macros to handle insertion and deletion of a bfd's sections. These
+ only handle the list pointers, ie. do not adjust section_count,
+ target_index etc. */
+#define bfd_section_list_remove(ABFD, PS) \
+ do \
+ { \
+ asection **_ps = PS; \
+ asection *_s = *_ps; \
+ *_ps = _s->next; \
+ if (_s->next == NULL) \
+ (ABFD)->section_tail = _ps; \
+ } \
+ while (0)
+#define bfd_section_list_insert(ABFD, PS, S) \
+ do \
+ { \
+ asection **_ps = PS; \
+ asection *_s = S; \
+ _s->next = *_ps; \
+ *_ps = _s; \
+ if (_s->next == NULL) \
+ (ABFD)->section_tail = &_s->next; \
+ } \
+ while (0)
+
+void
+bfd_section_list_clear PARAMS ((bfd *));
+
asection *
bfd_get_section_by_name PARAMS ((bfd *abfd, const char *name));
/* BFD back-end for CISCO crash dumps.
- Copyright 1994, 1997, 1999, 2000, 2001 Free Software Foundation, Inc.
+ Copyright 1994, 1997, 1999, 2000, 2001, 2002
+ Free Software Foundation, Inc.
This file is part of BFD, the Binary File Descriptor library.
break;
}
- abfd->sections = NULL;
- abfd->section_count = 0;
-
- /* Create a ".reg" section to allow access to the saved
- registers. */
+ /* Create a ".data" section that maps the entire file, which is
+ essentially a dump of the target system's RAM. */
- asect = (asection *) bfd_zmalloc ((bfd_size_type) sizeof (asection));
+ asect = bfd_make_section_anyway (abfd, ".data");
if (asect == NULL)
goto error_return;
- asect->name = ".reg";
- asect->flags = SEC_HAS_CONTENTS;
- asect->vma = 0;
- asect->filepos = bfd_get_32 (abfd, crashinfo.registers) - rambase;
- /* Since we don't know the exact size of the saved register info,
- choose a register section size that is either the remaining part
- of the file, or 1024, whichever is smaller. */
- nread = statbuf.st_size - asect->filepos;
- asect->_raw_size = (nread < 1024) ? nread : 1024;
- asect->next = abfd->sections;
- abfd->sections = asect;
- ++abfd->section_count;
+ asect->flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS;
+ /* The size of memory is the size of the core file itself. */
+ asect->_raw_size = statbuf.st_size;
+ asect->vma = rambase;
+ asect->filepos = 0;
/* Create a ".crash" section to allow access to the saved
crash information. */
- asect = (asection *) bfd_zmalloc ((bfd_size_type) sizeof (asection));
+ asect = bfd_make_section_anyway (abfd, ".crash");
if (asect == NULL)
goto error_return;
- asect->name = ".crash";
asect->flags = SEC_HAS_CONTENTS;
asect->vma = 0;
asect->filepos = crashinfo_offset;
asect->_raw_size = sizeof (crashinfo);
- asect->next = abfd->sections;
- abfd->sections = asect;
- ++abfd->section_count;
- /* Create a ".data" section that maps the entire file, which is
- essentially a dump of the target system's RAM. */
+ /* Create a ".reg" section to allow access to the saved
+ registers. */
- asect = (asection *) bfd_zmalloc ((bfd_size_type) sizeof (asection));
+ asect = bfd_make_section_anyway (abfd, ".reg");
if (asect == NULL)
goto error_return;
- asect->name = ".data";
- asect->flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS;
- /* The size of memory is the size of the core file itself. */
- asect->_raw_size = statbuf.st_size;
- asect->vma = rambase;
- asect->filepos = 0;
- asect->next = abfd->sections;
- abfd->sections = asect;
- ++abfd->section_count;
+ asect->flags = SEC_HAS_CONTENTS;
+ asect->vma = 0;
+ asect->filepos = bfd_get_32 (abfd, crashinfo.registers) - rambase;
+ /* Since we don't know the exact size of the saved register info,
+ choose a register section size that is either the remaining part
+ of the file, or 1024, whichever is smaller. */
+ nread = statbuf.st_size - asect->filepos;
+ asect->_raw_size = (nread < 1024) ? nread : 1024;
return abfd->xvec;
and there is an error of some kind. */
error_return:
- {
- sec_ptr nextsect;
- for (asect = abfd->sections; asect != NULL;)
- {
- nextsect = asect->next;
- free (asect);
- asect = nextsect;
- }
- free (abfd->tdata.cisco_core_data);
- return NULL;
- }
+ bfd_release (abfd, abfd->tdata.any);
+ abfd->tdata.any = NULL;
+ bfd_section_list_clear (abfd);
+ return NULL;
}
static const bfd_target *
/* Support for the generic parts of most COFF variants, for BFD.
Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
- 2000, 2001
+ 2000, 2001, 2002
Free Software Foundation, Inc.
Written by Cygnus Support.
{
if (*ps == section)
{
- *ps = (*ps)->next;
+ bfd_section_list_remove (abfd, ps);
--abfd->section_count;
break;
}
if (p->type == bfd_indirect_link_order)
p->u.indirect.section->flags &= ~SEC_HAS_CONTENTS;
(*secpp)->link_order_head = NULL;
- *secpp = (*secpp)->next;
+ bfd_section_list_remove (abfd, secpp);
--abfd->section_count;
break;
*secpp != o;
secpp = &(*secpp)->next)
;
- *secpp = (*secpp)->next;
+ bfd_section_list_remove (abfd, secpp);
--abfd->section_count;
continue;
/* MIPS-specific support for 64-bit ELF
- Copyright 1996, 1997, 1998, 1999, 2000, 2001
+ Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002
Free Software Foundation, Inc.
Ian Lance Taylor, Cygnus Support
Linker support added by Mark Mitchell, CodeSourcery, LLC.
if (p->type == bfd_indirect_link_order)
p->u.indirect.section->flags &=~ SEC_HAS_CONTENTS;
(*secpp)->link_order_head = NULL;
- *secpp = (*secpp)->next;
+ bfd_section_list_remove (abfd, secpp);
--abfd->section_count;
break;
*secpp != o;
secpp = &(*secpp)->next)
;
- *secpp = (*secpp)->next;
+ bfd_section_list_remove (abfd, secpp);
--abfd->section_count;
continue;
/* MMIX-specific support for 64-bit ELF.
- Copyright (C) 2001 Free Software Foundation, Inc.
+ Copyright 2001, 2002 Free Software Foundation, Inc.
Contributed by Hans-Peter Nilsson <hp@bitrange.com>
This file is part of BFD, the Binary File Descriptor library.
if (bfd_get_section_flags (abfd, reg_section) & SEC_HAS_CONTENTS)
_bfd_abort (__FILE__, __LINE__, _("Register section has contents\n"));
- /* FIXME: This does not seem like the proper way to kill a section,
- but it's the way it's done elsewhere, like elf64-alpha.c. */
/* Really remove the section. */
for (secpp = &abfd->sections;
*secpp != reg_section;
secpp = &(*secpp)->next)
;
- *secpp = (*secpp)->next;
+ bfd_section_list_remove (abfd, secpp);
--abfd->section_count;
}
/* BFD back-end for HPPA BSD core files.
- Copyright 1993, 1994, 1995, 1998, 1999, 2001
+ Copyright 1993, 1994, 1995, 1998, 1999, 2001, 2002
Free Software Foundation, Inc.
This file is part of BFD, the Binary File Descriptor library.
clicksz * u.u_ssize,
NBPG * (USIZE + KSTAKSIZE)
+ clicksz * u.u_dsize, 2);
+ if (core_stacksec (abfd) == NULL)
+ goto fail;
core_stacksec (abfd)->vma = USRSTACK;
core_datasec (abfd) = make_bfd_asection (abfd, ".data",
+ SEC_HAS_CONTENTS,
clicksz * u.u_dsize,
NBPG * (USIZE + KSTAKSIZE), 2);
+ if (core_datasec (abfd) == NULL)
+ goto fail;
core_datasec (abfd)->vma = UDATASEG;
core_regsec (abfd) = make_bfd_asection (abfd, ".reg",
SEC_HAS_CONTENTS,
KSTAKSIZE * NBPG,
NBPG * USIZE, 2);
+ if (core_regsec (abfd) == NULL)
+ goto fail;
core_regsec (abfd)->vma = 0;
strncpy (core_command (abfd), u.u_comm, MAXCOMLEN + 1);
core_signal (abfd) = u.u_code;
return abfd->xvec;
+
+ fail:
+ bfd_release (abfd, abfd->tdata.any);
+ abfd->tdata.any = NULL;
+ bfd_section_list_clear (abfd);
+ return NULL;
}
static char *
/* BFD back-end for HP/UX core files.
- Copyright 1993, 1994, 1996, 1998, 1999, 2001
+ Copyright 1993, 1994, 1996, 1998, 1999, 2001, 2002
Free Software Foundation, Inc.
Written by Stu Grossman, Cygnus Support.
Converted to back-end form by Ian Lance Taylor, Cygnus SUpport
core_header.len,
(int) &proc_info - (int) & proc_info.hw_regs,
2))
- return NULL;
+ goto fail;
}
else
{
core_header.len,
(int) &proc_info - (int) & proc_info.hw_regs,
2))
- return NULL;
+ goto fail;
}
/* We always make one of these sections, for every thread. */
sprintf (secname, ".reg/%d", core_kernel_thread_id (abfd));
core_header.len,
(int) &proc_info - (int) & proc_info.hw_regs,
2))
- return NULL;
+ goto fail;
}
core_signal (abfd) = proc_info.sig;
if (bfd_seek (abfd, (file_ptr) core_header.len, SEEK_CUR) != 0)
if (!make_bfd_asection (abfd, ".data",
SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS,
core_header.len, core_header.addr, 2))
- return NULL;
+ goto fail;
bfd_seek (abfd, (file_ptr) core_header.len, SEEK_CUR);
good_sections++;
unknown_sections++;
break;
- default: return 0; /*unrecognized core file type */
+ default:
+ goto fail; /*unrecognized core file type */
}
}
abfd->filename);
return abfd->xvec;
+
+ fail:
+ bfd_release (abfd, core_hdr (abfd));
+ core_hdr (abfd) = NULL;
+ bfd_section_list_clear (abfd);
+ return NULL;
}
static char *
/* BFD back-end for Irix core files.
- Copyright 1993, 1994, 1996, 1999, 2001 Free Software Foundation, Inc.
+ Copyright 1993, 1994, 1996, 1999, 2001, 2002
+ Free Software Foundation, Inc.
Written by Stu Grossman, Cygnus Support.
Converted to back-end form by Ian Lance Taylor, Cygnus Support
core_signal (abfd) = coreout.c_sigcause;
if (bfd_seek (abfd, coreout.c_vmapoffset, SEEK_SET) != 0)
- return NULL;
+ goto fail;
for (i = 0; i < coreout.c_nvmap; i++)
{
vmap.v_len,
vmap.v_vaddr,
vmap.v_offset))
- return NULL;
+ goto fail;
}
/* Make sure that the regs are contiguous within the core file. */
if (idg->i_offset + idg->i_len != idf->i_offset
|| idf->i_offset + idf->i_len != ids->i_offset)
- return 0; /* Can't deal with non-contig regs */
+ goto fail; /* Can't deal with non-contig regs */
if (bfd_seek (abfd, idg->i_offset, SEEK_SET) != 0)
- return NULL;
+ goto fail;
- make_bfd_asection (abfd, ".reg",
- SEC_HAS_CONTENTS,
- idg->i_len + idf->i_len + ids->i_len,
- 0,
- idg->i_offset);
+ if (!make_bfd_asection (abfd, ".reg",
+ SEC_HAS_CONTENTS,
+ idg->i_len + idf->i_len + ids->i_len,
+ 0,
+ idg->i_offset))
+ goto fail;
/* OK, we believe you. You're a core file (sure, sure). */
bfd_default_set_arch_mach (abfd, bfd_arch_mips, 0);
return abfd->xvec;
+
+ fail:
+ bfd_release (abfd, core_hdr (abfd));
+ core_hdr (abfd) = NULL;
+ bfd_section_list_clear (abfd);
+ return NULL;
}
static char *
/* BFD back end for Lynx core files
- Copyright 1993, 1994, 1995, 2001 Free Software Foundation, Inc.
+ Copyright 1993, 1994, 1995, 2001, 2002 Free Software Foundation, Inc.
Written by Stu Grossman of Cygnus Support.
This file is part of BFD, the Binary File Descriptor library.
threadp = (core_st_t *) bfd_alloc (abfd, tcontext_size);
if (!threadp)
- return NULL;
+ goto fail;
/* Save thread contexts */
if (bfd_seek (abfd, (file_ptr) pagesize, SEEK_SET) != 0)
- return NULL;
+ goto fail;
if (bfd_bread ((void *) threadp, tcontext_size, abfd) != tcontext_size)
{
/* Probably too small to be a core file */
if (bfd_get_error () != bfd_error_system_call)
bfd_set_error (bfd_error_wrong_format);
- return NULL;
+ goto fail;
}
core_signal (abfd) = threadp->currsig;
pss.slimit,
pagesize + tcontext_size);
if (!newsect)
- return NULL;
+ goto fail;
newsect = make_bfd_asection (abfd, ".data",
SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS,
#endif
);
if (!newsect)
- return NULL;
+ goto fail;
/* And, now for the .reg/XXX pseudo sections. Each thread has it's own
.reg/XXX section, where XXX is the thread id (without leading zeros). The
0,
pagesize);
if (!newsect)
- return NULL;
+ goto fail;
for (secnum = 0; secnum < pss.threadcnt; secnum++)
{
0,
pagesize + secnum * sizeof (core_st_t));
if (!newsect)
- return NULL;
+ goto fail;
}
return abfd->xvec;
+
+ fail:
+ bfd_release (abfd, core_hdr (abfd));
+ core_hdr (abfd) = NULL;
+ bfd_section_list_clear (abfd);
+ return NULL;
}
char *
/* BFD back end for NetBSD style core files
- Copyright 1988, 1989, 1991, 1992, 1993, 1996, 1998, 1999, 2000, 2001
+ Copyright 1988, 1989, 1991, 1992, 1993, 1996, 1998, 1999, 2000, 2001,
+ 2002
Free Software Foundation, Inc.
Written by Paul Kranenburg, EUR
amt = sizeof (struct netbsd_core_struct);
rawptr = (struct netbsd_core_struct *) bfd_zalloc (abfd, amt);
if (rawptr == NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- return 0;
- }
+ return 0;
rawptr->core = core;
abfd->tdata.netbsd_core_data = rawptr;
offset = core.c_hdrsize;
for (i = 0; i < core.c_nseg; i++)
{
+ const char *sname;
+ flagword flags;
if (bfd_seek (abfd, offset, SEEK_SET) != 0)
goto punt;
offset += core.c_seghdrsize;
- amt = sizeof (asection);
- asect = (asection *) bfd_zalloc (abfd, amt);
- if (asect == NULL)
+ switch (CORE_GETFLAG (coreseg))
{
- bfd_set_error (bfd_error_no_memory);
- goto punt;
+ case CORE_CPU:
+ sname = ".reg";
+ flags = SEC_ALLOC + SEC_HAS_CONTENTS;
+ break;
+ case CORE_DATA:
+ sname = ".data";
+ flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
+ break;
+ case CORE_STACK:
+ sname = ".stack";
+ flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
+ break;
+ default:
+ sname = ".unknown";
+ flags = SEC_ALLOC + SEC_HAS_CONTENTS;
+ break;
}
+ asect = bfd_make_section_anyway (abfd, sname);
+ if (asect == NULL)
+ goto punt;
+ asect->flags = flags;
asect->_raw_size = coreseg.c_size;
asect->vma = coreseg.c_addr;
asect->filepos = offset;
asect->alignment_power = 2;
- asect->next = abfd->sections;
- abfd->sections = asect;
- abfd->section_count++;
+
offset += coreseg.c_size;
- switch (CORE_GETFLAG(coreseg))
+#ifdef CORE_FPU_OFFSET
+ switch (CORE_GETFLAG (coreseg))
{
case CORE_CPU:
- asect->name = ".reg";
- asect->flags = SEC_ALLOC + SEC_HAS_CONTENTS;
-#ifdef CORE_FPU_OFFSET
/* Hackish... */
asect->_raw_size = CORE_FPU_OFFSET;
- amt = sizeof (asection);
- asect2 = (asection *) bfd_zalloc (abfd, amt);
+ asect2 = bfd_make_section_anyway (abfd, ".reg2");
if (asect2 == NULL)
- {
- bfd_set_error (bfd_error_no_memory);
- goto punt;
- }
+ goto punt;
asect2->_raw_size = coreseg.c_size - CORE_FPU_OFFSET;
asect2->vma = 0;
asect2->filepos = asect->filepos + CORE_FPU_OFFSET;
asect2->alignment_power = 2;
- asect2->next = abfd->sections;
- asect2->name = ".reg2";
asect2->flags = SEC_ALLOC + SEC_HAS_CONTENTS;
- abfd->sections = asect2;
- abfd->section_count++;
-#endif
-
- break;
- case CORE_DATA:
- asect->name = ".data";
- asect->flags = SEC_ALLOC+SEC_LOAD+SEC_HAS_CONTENTS;
- break;
- case CORE_STACK:
- asect->name = ".stack";
- asect->flags = SEC_ALLOC+SEC_LOAD+SEC_HAS_CONTENTS;
break;
}
+#endif
}
/* OK, we believe you. You're a core file (sure, sure). */
return abfd->xvec;
punt:
- {
- asection *anext;
- for (asect = abfd->sections; asect; asect = anext)
- {
- anext = asect->next;
- free ((void *) asect);
- }
- }
-
- free ((void *) rawptr);
- abfd->tdata.netbsd_core_data = NULL;
- abfd->sections = NULL;
- abfd->section_count = 0;
+ bfd_release (abfd, abfd->tdata.any);
+ abfd->tdata.any = NULL;
+ bfd_section_list_clear (abfd);
return 0;
}
/* BFD back-end for OSF/1 core files.
- Copyright 1993, 1994, 1995, 1998, 1999, 2001
+ Copyright 1993, 1994, 1995, 1998, 1999, 2001, 2002
Free Software Foundation, Inc.
This file is part of BFD, the Binary File Descriptor library.
(bfd_size_type) core_scnhdr.size,
(bfd_vma) core_scnhdr.vaddr,
(file_ptr) core_scnhdr.scnptr))
- return NULL;
+ goto fail;
}
/* OK, we believe you. You're a core file (sure, sure). */
return abfd->xvec;
+
+ fail:
+ bfd_release (abfd, core_hdr (abfd));
+ core_hdr (abfd) = NULL;
+ bfd_section_list_clear (abfd);
+ return NULL;
}
static char *
/* BFD backend for core files which use the ptrace_user structure
- Copyright 1993, 1994, 1995, 1996, 1998, 1999, 2001
+ Copyright 1993, 1994, 1995, 1996, 1998, 1999, 2001, 2002
Free Software Foundation, Inc.
The structure of this file is based on trad-core.c written by John Gilmore
of Cygnus Support.
rawptr->u = u; /*Copy the uarea into the tdata part of the bfd */
- /* Create the sections. This is raunchy, but bfd_close wants to free
- them separately. */
+ /* Create the sections. */
- amt = sizeof (asection);
- core_stacksec (abfd) = (asection *) bfd_zalloc (abfd, amt);
+ core_stacksec (abfd) = bfd_make_section_anyway (abfd, ".stack");
if (core_stacksec (abfd) == NULL)
- return NULL;
- core_datasec (abfd) = (asection *) bfd_zalloc (abfd, amt);
+ goto fail;
+ core_datasec (abfd) = bfd_make_section_anyway (abfd, ".data");
if (core_datasec (abfd) == NULL)
- return NULL;
- core_regsec (abfd) = (asection *) bfd_zalloc (abfd, amt);
+ goto fail;
+ core_regsec (abfd) = bfd_make_section_anyway (abfd, ".reg");
if (core_regsec (abfd) == NULL)
- return NULL;
-
- core_stacksec (abfd)->name = ".stack";
- core_datasec (abfd)->name = ".data";
- core_regsec (abfd)->name = ".reg";
+ goto fail;
/* FIXME: Need to worry about shared memory, library data, and library
text. I don't think that any of these things are supported on the
core_datasec (abfd)->alignment_power = 2;
core_regsec (abfd)->alignment_power = 2;
- abfd->sections = core_stacksec (abfd);
- core_stacksec (abfd)->next = core_datasec (abfd);
- core_datasec (abfd)->next = core_regsec (abfd);
- abfd->section_count = 3;
-
return abfd->xvec;
+
+ fail:
+ bfd_release (abfd, abfd->tdata.any);
+ abfd->tdata.any = NULL;
+ bfd_section_list_clear (abfd);
+ return NULL;
}
char *
/* IBM RS/6000 "XCOFF" back-end for BFD.
Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000,
- 2001
+ 2001, 2002
Free Software Foundation, Inc.
FIXME: Can someone provide a transliteration of this name into ASCII?
Using the following chars caused a compiler warning on HIUX (so I replaced
if (!make_bfd_asection (abfd, ".stack",
SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS,
c_size, c_stackend - c_size, c_stack))
- return NULL;
+ goto fail;
/* .reg section for all registers. */
if (!make_bfd_asection (abfd, ".reg",
SEC_HAS_CONTENTS,
c_regsize, (bfd_vma) 0, c_regoff))
- return NULL;
+ goto fail;
/* .ldinfo section.
To actually find out how long this section is in this particular
if (!make_bfd_asection (abfd, ".ldinfo",
SEC_HAS_CONTENTS,
c_lsize, (bfd_vma) 0, c_loader))
- return NULL;
+ goto fail;
#ifndef CORE_VERSION_1
/* .data section if present.
(bfd_vma)
CDATA_ADDR (core.old.c_u.u_dsize),
c_stack + c_size))
- return NULL;
+ goto fail;
}
#endif
c_datasize,
(bfd_vma) CDATA_ADDR (c_datasize),
c_data))
- return NULL;
+ goto fail;
}
/* .data sections from loaded objects. */
while (1)
{
if (bfd_seek (abfd, c_loader, SEEK_SET) != 0)
- return NULL;
+ goto fail;
if (bfd_bread (&ldinfo, size, abfd) != size)
- return NULL;
+ goto fail;
if (proc64)
{
if (!make_bfd_asection (abfd, ".data",
SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS,
ldi_datasize, ldi_dataorg, ldi_core))
- return NULL;
+ goto fail;
if (ldi_next == 0)
break;
bfd_size_type i;
if (bfd_seek (abfd, c_vmm, SEEK_SET) != 0)
- return NULL;
+ goto fail;
for (i = 0; i < c_vmregions; i++)
{
size = CORE_NEW (core) ? sizeof (vminfo.new) : sizeof (vminfo.old);
if (bfd_bread (&vminfo, size, abfd) != size)
- return NULL;
+ goto fail;
if (CORE_NEW (core))
{
SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS,
vminfo_size, vminfo_addr,
vminfo_offset))
- return NULL;
+ goto fail;
}
}
}
#endif
return abfd->xvec; /* This is garbage for now. */
+
+ fail:
+ bfd_release (abfd, abfd->tdata.any);
+ abfd->tdata.any = NULL;
+ bfd_section_list_clear (abfd);
+ return NULL;
}
/* Return `true' if given core is from the given executable. */
/* BFD back end for SCO5 core files (U-area and raw sections)
- Copyright 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+ Copyright 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
Written by Jouke Numan <jnuman@hiscom.nl>
This file is part of BFD, the Binary File Descriptor library.
{
/* Old version, no section heads, read info from user struct */
- u = read_uarea(abfd, coffsets.u_user);
+ u = read_uarea (abfd, coffsets.u_user);
if (! u)
- return NULL;
+ goto fail;
if (!make_bfd_asection (abfd, ".reg", SEC_HAS_CONTENTS,
(bfd_size_type) coffsets.u_usize,
0 - (bfd_vma) u->u_ar0,
(file_ptr) coffsets.u_user))
- return NULL;
+ goto fail;
if (!make_bfd_asection (abfd, ".data",
SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS,
+ u->u_exdata.ux_bsize),
(bfd_vma) u->u_exdata.ux_datorg,
(file_ptr) coffsets.u_data))
- return NULL;
+ goto fail;
if (!make_bfd_asection (abfd, ".stack",
SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS,
(bfd_size_type) u->u_ssize * NBPC,
(bfd_vma) u->u_sub,
(file_ptr) coffsets.u_stack))
- return NULL;
+ goto fail;
return abfd->xvec; /* Done for version 1 */
}
|| (chead.cs_x.csx_magic != COREMAGIC_NUMBER))
{
bfd_set_error (bfd_error_wrong_format);
- return NULL;
+ goto fail;
}
/* OK, we believe you. You're a core file (sure, sure). */
!= sizeof chead))
{
bfd_set_error (bfd_error_wrong_format);
- return NULL;
+ goto fail;
}
switch (chead.cs_stype)
if (chead.cs_x.csx_magic != COREMAGIC_NUMBER)
{
bfd_set_error (bfd_error_wrong_format);
- return NULL;
+ goto fail;
}
secname = NULL;
nsecs++; /* MAGIC not in section cnt!*/
break;
case CORES_UAREA: /* U-area, read in tdata */
- u = read_uarea(abfd, chead.cs_sseek);
+ u = read_uarea (abfd, chead.cs_sseek);
if (! u)
- return NULL;
+ goto fail;
/* This is tricky. As the "register section", we give them
the entire upage and stack. u.u_ar0 points to where
(bfd_size_type) chead.cs_vsize,
(bfd_vma) chead.cs_vaddr,
(file_ptr) chead.cs_sseek))
- return NULL;
+ goto fail;
}
return abfd->xvec;
+ fail:
+ if (abfd->tdata.any)
+ {
+ bfd_release (abfd, abfd->tdata.any);
+ abfd->tdata.any = NULL;
+ }
+ bfd_section_list_clear (abfd);
+ return NULL;
}
char *
/* Object file "section" support for the BFD library.
Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
- 2000, 2001
+ 2000, 2001, 2002
Free Software Foundation, Inc.
Written by Cygnus Support.
.#define bfd_get_section_size_after_reloc(section) \
. ((section)->reloc_done ? (section)->_cooked_size \
. : (abort (), (bfd_size_type) 1))
+.
+.{* Macros to handle insertion and deletion of a bfd's sections. These
+. only handle the list pointers, ie. do not adjust section_count,
+. target_index etc. *}
+.#define bfd_section_list_remove(ABFD, PS) \
+. do \
+. { \
+. asection **_ps = PS; \
+. asection *_s = *_ps; \
+. *_ps = _s->next; \
+. if (_s->next == NULL) \
+. (ABFD)->section_tail = _ps; \
+. } \
+. while (0)
+.#define bfd_section_list_insert(ABFD, PS, S) \
+. do \
+. { \
+. asection **_ps = PS; \
+. asection *_s = S; \
+. _s->next = *_ps; \
+. *_ps = _s; \
+. if (_s->next == NULL) \
+. (ABFD)->section_tail = &_s->next; \
+. } \
+. while (0)
+.
*/
/* We use a macro to initialize the static asymbol structures because
newsect->id = section_id;
newsect->index = abfd->section_count;
- newsect->flags = SEC_NO_FLAGS;
-
- newsect->userdata = NULL;
- newsect->contents = NULL;
- newsect->next = (asection *) NULL;
- newsect->relocation = (arelent *) NULL;
- newsect->reloc_count = 0;
- newsect->line_filepos = 0;
newsect->owner = abfd;
- newsect->comdat = NULL;
/* Create a symbol whose only job is to point to this section. This
is useful for things like relocs which are relative to the base
/*
FUNCTION
+ bfd_section_list_clear
+
+SYNOPSIS
+ void bfd_section_list_clear (bfd *);
+
+DESCRIPTION
+ Clears the section list, and also resets the section count and
+ hash table entries.
+*/
+
+void
+bfd_section_list_clear (abfd)
+ bfd *abfd;
+{
+ abfd->sections = NULL;
+ abfd->section_tail = &abfd->sections;
+ abfd->section_count = 0;
+ memset ((PTR) abfd->section_htab.table, 0,
+ abfd->section_htab.size * sizeof (struct bfd_hash_entry *));
+}
+
+/*
+FUNCTION
bfd_get_section_by_name
SYNOPSIS
for (spp = &os->owner->sections; *spp; spp = &(*spp)->next)
if (*spp == os)
{
- *spp = os->next;
- if (os->next == NULL)
- os->owner->section_tail = spp;
+ bfd_section_list_remove (os->owner, spp);
os->owner->section_count--;
break;
}
/* BFD backend for SunOS binaries.
- Copyright 1990, 1991, 1992, 1994, 1995, 1996, 1997, 1998, 2000, 2001
+ Copyright 1990, 1991, 1992, 1994, 1995, 1996, 1997, 1998, 2000, 2001,
+ 2002
Free Software Foundation, Inc.
Written by Cygnus Support.
bfd *dynobj;
struct sunos_dynamic_info *dinfo;
unsigned long need;
+ asection **ps;
/* Make sure we have all the required sections. */
if (info->hash->creator == abfd->xvec)
want, because that one still implies that the section takes up
space in the output file. If this is the first object we have
seen, we must preserve the dynamic sections we just created. */
- if (abfd != dynobj)
- abfd->sections = NULL;
- else
+ for (ps = &abfd->sections; *ps != NULL; )
{
- asection *s;
-
- for (s = abfd->sections;
- (s->flags & SEC_LINKER_CREATED) == 0;
- s = s->next)
- ;
- abfd->sections = s;
+ if (abfd != dynobj || ((*ps)->flags & SEC_LINKER_CREATED) == 0)
+ bfd_section_list_remove (abfd, ps);
+ else
+ ps = &(*ps)->next;
}
/* The native linker seems to just ignore dynamic objects when -r is
/* BFD back end for traditional Unix core files (U-area and raw sections)
Copyright 1988, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999,
- 2000, 2001
+ 2000, 2001, 2002
Free Software Foundation, Inc.
Written by John Gilmore of Cygnus Support.
rawptr->u = u; /*Copy the uarea into the tdata part of the bfd */
- /* Create the sections. This is raunchy, but bfd_close wants to free
- them separately. */
+ /* Create the sections. */
- amt = sizeof (asection);
- core_stacksec(abfd) = (asection *) bfd_zalloc (abfd, amt);
+ core_stacksec(abfd) = bfd_make_section_anyway (abfd, ".stack");
if (core_stacksec (abfd) == NULL)
- return NULL;
- amt = sizeof (asection);
- core_datasec (abfd) = (asection *) bfd_zalloc (abfd, amt);
+ goto fail;
+ core_datasec (abfd) = bfd_make_section_anyway (abfd, ".data");
if (core_datasec (abfd) == NULL)
- return NULL;
- amt = sizeof (asection);
- core_regsec (abfd) = (asection *) bfd_zalloc (abfd, amt);
+ goto fail;
+ core_regsec (abfd) = bfd_make_section_anyway (abfd, ".reg");
if (core_regsec (abfd) == NULL)
- return NULL;
-
- core_stacksec (abfd)->name = ".stack";
- core_datasec (abfd)->name = ".data";
- core_regsec (abfd)->name = ".reg";
+ goto fail;
core_stacksec (abfd)->flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
core_datasec (abfd)->flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
core_datasec (abfd)->alignment_power = 2;
core_regsec (abfd)->alignment_power = 2;
- abfd->sections = core_stacksec (abfd);
- core_stacksec (abfd)->next = core_datasec (abfd);
- core_datasec (abfd)->next = core_regsec (abfd);
- abfd->section_count = 3;
-
return abfd->xvec;
+
+ fail:
+ bfd_release (abfd, abfd->tdata.any);
+ abfd->tdata.any = NULL;
+ bfd_section_list_clear (abfd);
+ return NULL;
}
char *
/* POWER/PowerPC XCOFF linker support.
- Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001
+ Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
Free Software Foundation, Inc.
Written by Ian Lance Taylor <ian@cygnus.com>, Cygnus Support.
{
boolean saw_contents;
int indx;
- asection **op, **prev;
+ asection **op;
file_ptr sofar;
/* Insert .pad sections before every section which has
contents and is loaded, if it is preceded by some other
section which has contents and is loaded. */
saw_contents = true;
- for (op = &abfd->sections, prev = NULL;
- *op != NULL; prev = op, op = &(*op)->next)
+ for (op = &abfd->sections; *op != NULL; op = &(*op)->next)
{
if (strcmp ((*op)->name, ".pad") == 0)
saw_contents = false;
saw_contents = true;
else
{
- asection *n, *hold, **st;
+ asection *n, **st;
/* Create a pad section and place it before the section
that needs padding. This requires unlinking and
- relinking the bfd's sections list.
-
- sections = S1
- . S1.next = S2
- . S2.next = S3
- . S3.next = NULL
- section_tail = &S3.next */
+ relinking the bfd's section list. */
- hold = *op;
st = abfd->section_tail;
-
n = bfd_make_section_anyway (abfd, ".pad");
n->flags = SEC_HAS_CONTENTS;
n->alignment_power = 0;
-
- if (NULL == prev)
- abfd->sections = n;
- else
- (*prev)->next = n;
-
- n->next = hold;
- *st = NULL;
- abfd->section_tail = st;
+ BFD_ASSERT (*st == n);
+ bfd_section_list_remove (abfd, st);
+ bfd_section_list_insert (abfd, op, n);
+
+ op = &n->next;
saw_contents = false;
}
}