From 9e7b37b31f29ad3b8321d15e589ed5de550c56d3 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Sat, 5 Jan 2002 13:11:33 +0000 Subject: [PATCH] * 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. --- bfd/ChangeLog | 31 ++++++++++++++++ bfd/aix386-core.c | 93 ++++++++++++++++++++-------------------------- bfd/aoutf1.h | 28 ++++---------- bfd/bfd-in2.h | 29 +++++++++++++++ bfd/cisco-core.c | 73 +++++++++++++----------------------- bfd/coffcode.h | 4 +- bfd/elf32-mips.c | 4 +- bfd/elf64-mips.c | 6 +-- bfd/elf64-mmix.c | 6 +-- bfd/hppabsd-core.c | 14 ++++++- bfd/hpux-core.c | 19 +++++++--- bfd/irix-core.c | 28 +++++++++----- bfd/lynx-core.c | 22 +++++++---- bfd/netbsd-core.c | 85 +++++++++++++++++------------------------- bfd/osf-core.c | 10 ++++- bfd/ptrace-core.c | 33 +++++++--------- bfd/rs6000-core.c | 30 +++++++++------ bfd/sco5-core.c | 32 ++++++++++------ bfd/section.c | 64 ++++++++++++++++++++++++------- bfd/sunos.c | 19 ++++------ bfd/trad-core.c | 35 +++++++---------- bfd/xcofflink.c | 33 +++++----------- 22 files changed, 380 insertions(+), 318 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 37614e46be4..be4fe732a6c 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,5 +1,36 @@ 2002-01-05 Alan Modra + * 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. diff --git a/bfd/aix386-core.c b/bfd/aix386-core.c index 10cfb519e07..591397e4a2e 100644 --- a/bfd/aix386-core.c +++ b/bfd/aix386-core.c @@ -2,7 +2,7 @@ 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 . Converted to back end form by Ian Lance Taylor . @@ -108,96 +108,85 @@ aix386_core_file_p (abfd) 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; } diff --git a/bfd/aoutf1.h b/bfd/aoutf1.h index ff02136562c..0f773a18a8c 100644 --- a/bfd/aoutf1.h +++ b/bfd/aoutf1.h @@ -1,6 +1,6 @@ /* 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. @@ -641,6 +641,8 @@ sunos4_core_file_p (abfd) { loser: bfd_release (abfd, (char *) mergem); + abfd->tdata.any = NULL; + bfd_section_list_clear (abfd); return 0; } @@ -667,31 +669,24 @@ sunos4_core_file_p (abfd) 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; @@ -719,13 +714,6 @@ sunos4_core_file_p (abfd) 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; } diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index 29831386496..95a3d2e35bc 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -1372,6 +1372,35 @@ extern const struct symbol_cache_entry * const bfd_ind_symbol; #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)); diff --git a/bfd/cisco-core.c b/bfd/cisco-core.c index f9878a2cf0a..db87466ff31 100644 --- a/bfd/cisco-core.c +++ b/bfd/cisco-core.c @@ -1,5 +1,6 @@ /* 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. @@ -237,58 +238,43 @@ cisco_core_file_validate (abfd, crash_info_loc) 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; @@ -296,17 +282,10 @@ cisco_core_file_validate (abfd, crash_info_loc) 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 * diff --git a/bfd/coffcode.h b/bfd/coffcode.h index b5bd4429c77..0b185a56be1 100644 --- a/bfd/coffcode.h +++ b/bfd/coffcode.h @@ -1,6 +1,6 @@ /* 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. @@ -1680,7 +1680,7 @@ coff_set_alignment_hook (abfd, section, scnhdr) { if (*ps == section) { - *ps = (*ps)->next; + bfd_section_list_remove (abfd, ps); --abfd->section_count; break; } diff --git a/bfd/elf32-mips.c b/bfd/elf32-mips.c index 63e6e023db0..a4007ef4685 100644 --- a/bfd/elf32-mips.c +++ b/bfd/elf32-mips.c @@ -5177,7 +5177,7 @@ _bfd_mips_elf_final_link (abfd, info) 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; @@ -5547,7 +5547,7 @@ _bfd_mips_elf_final_link (abfd, info) *secpp != o; secpp = &(*secpp)->next) ; - *secpp = (*secpp)->next; + bfd_section_list_remove (abfd, secpp); --abfd->section_count; continue; diff --git a/bfd/elf64-mips.c b/bfd/elf64-mips.c index 026edc88821..75d456ac376 100644 --- a/bfd/elf64-mips.c +++ b/bfd/elf64-mips.c @@ -1,5 +1,5 @@ /* 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. @@ -6392,7 +6392,7 @@ mips_elf64_final_link (abfd, info) 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; @@ -6676,7 +6676,7 @@ mips_elf64_final_link (abfd, info) *secpp != o; secpp = &(*secpp)->next) ; - *secpp = (*secpp)->next; + bfd_section_list_remove (abfd, secpp); --abfd->section_count; continue; diff --git a/bfd/elf64-mmix.c b/bfd/elf64-mmix.c index 552848ab006..3911976a252 100644 --- a/bfd/elf64-mmix.c +++ b/bfd/elf64-mmix.c @@ -1,5 +1,5 @@ /* 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 This file is part of BFD, the Binary File Descriptor library. @@ -1667,14 +1667,12 @@ mmix_elf_final_link (abfd, info) 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; } diff --git a/bfd/hppabsd-core.c b/bfd/hppabsd-core.c index dd0ffdabcf5..3fb76cc439c 100644 --- a/bfd/hppabsd-core.c +++ b/bfd/hppabsd-core.c @@ -1,5 +1,5 @@ /* 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. @@ -183,6 +183,8 @@ hppabsd_core_core_file_p (abfd) 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", @@ -190,17 +192,27 @@ hppabsd_core_core_file_p (abfd) + 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 * diff --git a/bfd/hpux-core.c b/bfd/hpux-core.c index e39df79d6ca..a8360228eb6 100644 --- a/bfd/hpux-core.c +++ b/bfd/hpux-core.c @@ -1,5 +1,5 @@ /* 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 @@ -246,7 +246,7 @@ hpux_core_core_file_p (abfd) core_header.len, (int) &proc_info - (int) & proc_info.hw_regs, 2)) - return NULL; + goto fail; } else { @@ -259,7 +259,7 @@ hpux_core_core_file_p (abfd) 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)); @@ -268,7 +268,7 @@ hpux_core_core_file_p (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) @@ -286,7 +286,7 @@ hpux_core_core_file_p (abfd) 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++; @@ -302,7 +302,8 @@ hpux_core_core_file_p (abfd) unknown_sections++; break; - default: return 0; /*unrecognized core file type */ + default: + goto fail; /*unrecognized core file type */ } } @@ -320,6 +321,12 @@ hpux_core_core_file_p (abfd) 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 * diff --git a/bfd/irix-core.c b/bfd/irix-core.c index 3ee3695b62d..c1a99acd525 100644 --- a/bfd/irix-core.c +++ b/bfd/irix-core.c @@ -1,5 +1,6 @@ /* 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 @@ -109,7 +110,7 @@ irix_core_core_file_p (abfd) 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++) { @@ -146,7 +147,7 @@ irix_core_core_file_p (abfd) vmap.v_len, vmap.v_vaddr, vmap.v_offset)) - return NULL; + goto fail; } /* Make sure that the regs are contiguous within the core file. */ @@ -157,21 +158,28 @@ irix_core_core_file_p (abfd) 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 * diff --git a/bfd/lynx-core.c b/bfd/lynx-core.c index 1d4a763d0dc..af513aca75c 100644 --- a/bfd/lynx-core.c +++ b/bfd/lynx-core.c @@ -1,5 +1,5 @@ /* 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. @@ -129,19 +129,19 @@ lynx_core_file_p (abfd) 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; @@ -152,7 +152,7 @@ lynx_core_file_p (abfd) pss.slimit, pagesize + tcontext_size); if (!newsect) - return NULL; + goto fail; newsect = make_bfd_asection (abfd, ".data", SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS, @@ -170,7 +170,7 @@ lynx_core_file_p (abfd) #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 @@ -185,7 +185,7 @@ lynx_core_file_p (abfd) 0, pagesize); if (!newsect) - return NULL; + goto fail; for (secnum = 0; secnum < pss.threadcnt; secnum++) { @@ -198,10 +198,16 @@ lynx_core_file_p (abfd) 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 * diff --git a/bfd/netbsd-core.c b/bfd/netbsd-core.c index 1c1a99ee048..2787c46eb89 100644 --- a/bfd/netbsd-core.c +++ b/bfd/netbsd-core.c @@ -1,5 +1,6 @@ /* 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 @@ -78,10 +79,7 @@ netbsd_core_file_p (abfd) 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; @@ -89,6 +87,8 @@ netbsd_core_file_p (abfd) 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; @@ -107,78 +107,63 @@ netbsd_core_file_p (abfd) 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; } diff --git a/bfd/osf-core.c b/bfd/osf-core.c index bafc72857bf..a514a2b2dad 100644 --- a/bfd/osf-core.c +++ b/bfd/osf-core.c @@ -1,5 +1,5 @@ /* 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. @@ -158,12 +158,18 @@ osf_core_core_file_p (abfd) (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 * diff --git a/bfd/ptrace-core.c b/bfd/ptrace-core.c index 998b1b487f1..f8db927ea86 100644 --- a/bfd/ptrace-core.c +++ b/bfd/ptrace-core.c @@ -1,5 +1,5 @@ /* 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. @@ -89,23 +89,17 @@ ptrace_unix_core_file_p (abfd) 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 @@ -132,12 +126,13 @@ ptrace_unix_core_file_p (abfd) 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 * diff --git a/bfd/rs6000-core.c b/bfd/rs6000-core.c index e6405f962c3..19ff4a4a77f 100644 --- a/bfd/rs6000-core.c +++ b/bfd/rs6000-core.c @@ -1,6 +1,6 @@ /* 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 @@ -462,13 +462,13 @@ rs6000coff_core_p (abfd) 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 @@ -477,7 +477,7 @@ rs6000coff_core_p (abfd) 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. @@ -494,7 +494,7 @@ rs6000coff_core_p (abfd) (bfd_vma) CDATA_ADDR (core.old.c_u.u_dsize), c_stack + c_size)) - return NULL; + goto fail; } #endif @@ -536,7 +536,7 @@ rs6000coff_core_p (abfd) c_datasize, (bfd_vma) CDATA_ADDR (c_datasize), c_data)) - return NULL; + goto fail; } /* .data sections from loaded objects. */ @@ -548,9 +548,9 @@ rs6000coff_core_p (abfd) 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) { @@ -571,7 +571,7 @@ rs6000coff_core_p (abfd) 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; @@ -584,7 +584,7 @@ rs6000coff_core_p (abfd) bfd_size_type i; if (bfd_seek (abfd, c_vmm, SEEK_SET) != 0) - return NULL; + goto fail; for (i = 0; i < c_vmregions; i++) { @@ -595,7 +595,7 @@ rs6000coff_core_p (abfd) 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)) { @@ -615,13 +615,19 @@ rs6000coff_core_p (abfd) 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. */ diff --git a/bfd/sco5-core.c b/bfd/sco5-core.c index a84ef45c5b1..b78ee59b2d9 100644 --- a/bfd/sco5-core.c +++ b/bfd/sco5-core.c @@ -1,5 +1,5 @@ /* 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 This file is part of BFD, the Binary File Descriptor library. @@ -176,15 +176,15 @@ sco5_core_file_p (abfd) { /* 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, @@ -192,14 +192,14 @@ sco5_core_file_p (abfd) + 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 */ } @@ -223,7 +223,7 @@ sco5_core_file_p (abfd) || (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). */ @@ -237,7 +237,7 @@ sco5_core_file_p (abfd) != sizeof chead)) { bfd_set_error (bfd_error_wrong_format); - return NULL; + goto fail; } switch (chead.cs_stype) @@ -246,15 +246,15 @@ sco5_core_file_p (abfd) 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 @@ -325,12 +325,20 @@ sco5_core_file_p (abfd) (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 * diff --git a/bfd/section.c b/bfd/section.c index 73567d9f64e..c1dc0b1b581 100644 --- a/bfd/section.c +++ b/bfd/section.c @@ -1,6 +1,6 @@ /* 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. @@ -560,6 +560,32 @@ CODE_FRAGMENT .#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 @@ -680,16 +706,7 @@ bfd_section_init (abfd, newsect) 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 @@ -725,6 +742,29 @@ SUBSECTION These are the functions exported by the section handling part of BFD. */ +/* +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 @@ -1357,9 +1397,7 @@ _bfd_strip_section_from_output (info, s) 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; } diff --git a/bfd/sunos.c b/bfd/sunos.c index 01eb57800f4..30fd019a24b 100644 --- a/bfd/sunos.c +++ b/bfd/sunos.c @@ -1,5 +1,6 @@ /* 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. @@ -877,6 +878,7 @@ sunos_add_dynamic_symbols (abfd, info, symsp, sym_countp, stringsp) 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) @@ -902,17 +904,12 @@ sunos_add_dynamic_symbols (abfd, info, symsp, sym_countp, stringsp) 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 diff --git a/bfd/trad-core.c b/bfd/trad-core.c index 829be0c92e9..aed0b50d1fc 100644 --- a/bfd/trad-core.c +++ b/bfd/trad-core.c @@ -1,6 +1,6 @@ /* 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. @@ -159,25 +159,17 @@ trad_unix_core_file_p (abfd) 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; @@ -234,12 +226,13 @@ trad_unix_core_file_p (abfd) 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 * diff --git a/bfd/xcofflink.c b/bfd/xcofflink.c index 19957698926..84b8e52ccae 100644 --- a/bfd/xcofflink.c +++ b/bfd/xcofflink.c @@ -1,5 +1,5 @@ /* 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 , Cygnus Support. @@ -3656,15 +3656,14 @@ _bfd_xcoff_bfd_final_link (abfd, info) { 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; @@ -3675,34 +3674,22 @@ _bfd_xcoff_bfd_final_link (abfd, info) 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; } } -- 2.30.2