/* Support for the generic parts of COFF, for BFD.
- Copyright (C) 1990-2020 Free Software Foundation, Inc.
+ Copyright (C) 1990-2021 Free Software Foundation, Inc.
Written by Cygnus Support.
This file is part of BFD, the Binary File Descriptor library.
for (; erel < erel_end; erel += relsz, irel++)
bfd_coff_swap_reloc_in (abfd, (void *) erel, (void *) irel);
- if (free_external != NULL)
- {
- free (free_external);
- free_external = NULL;
- }
+ free (free_external);
+ free_external = NULL;
if (cache && free_internal != NULL)
{
return internal_relocs;
error_return:
- if (free_external != NULL)
- free (free_external);
- if (free_internal != NULL)
- free (free_internal);
+ free (free_external);
+ free (free_internal);
return NULL;
}
internal_ptr->is_sym = TRUE;
/* PR 17512: Prevent buffer overrun. */
- if (symbol_ptr->u.syment.n_numaux > (raw_end - raw_src) / symesz)
+ if (symbol_ptr->u.syment.n_numaux > ((raw_end - 1) - raw_src) / symesz)
{
bfd_release (abfd, internal);
return NULL;
/* In XCOFF a debugging symbol can follow the
function symbol. */
- if (s->u.syment.n_scnum == N_DEBUG)
+ if (((size_t) ((char *) s - (char *) obj_raw_syments (abfd))
+ < obj_raw_syment_count (abfd) * sizeof (*s))
+ && s->u.syment.n_scnum == N_DEBUG)
s = s + 1 + s->u.syment.n_numaux;
/* S should now point to the .bf of the function. */
- if (s->u.syment.n_numaux)
+ if (((size_t) ((char *) s - (char *) obj_raw_syments (abfd))
+ < obj_raw_syment_count (abfd) * sizeof (*s))
+ && s->u.syment.n_numaux)
{
/* The linenumber is stored in the auxent. */
union internal_auxent *a = &((s + 1)->u.auxent);
key = s_comdat->name;
else
{
- if (CONST_STRNEQ (name, ".gnu.linkonce.")
+ if (startswith (name, ".gnu.linkonce.")
&& (key = strchr (name + sizeof (".gnu.linkonce.") - 1, '.')) != NULL)
key++;
else
.gnu.linkonce.*.<key>. */
if (((s_comdat != NULL) == (l_comdat != NULL)
&& strcmp (name, l->sec->name) == 0)
- || (l->sec->owner->flags & BFD_PLUGIN) != 0)
+ || (l->sec->owner->flags & BFD_PLUGIN) != 0
+ || (sec->owner->flags & BFD_PLUGIN) != 0)
{
/* The section has already been linked. See if we should
issue a warning. */
if ((o->flags & (SEC_DEBUGGING | SEC_LINKER_CREATED)) != 0
|| (o->flags & (SEC_ALLOC | SEC_LOAD | SEC_RELOC)) == 0)
o->gc_mark = 1;
- else if (CONST_STRNEQ (o->name, ".idata")
- || CONST_STRNEQ (o->name, ".pdata")
- || CONST_STRNEQ (o->name, ".xdata")
- || CONST_STRNEQ (o->name, ".rsrc"))
+ else if (startswith (o->name, ".idata")
+ || startswith (o->name, ".pdata")
+ || startswith (o->name, ".xdata")
+ || startswith (o->name, ".rsrc"))
o->gc_mark = 1;
if (o->gc_mark)
for (o = sub->sections; o != NULL; o = o->next)
{
if (((o->flags & (SEC_EXCLUDE | SEC_KEEP)) == SEC_KEEP
- || CONST_STRNEQ (o->name, ".vectors")
- || CONST_STRNEQ (o->name, ".ctors")
- || CONST_STRNEQ (o->name, ".dtors"))
+ || startswith (o->name, ".vectors")
+ || startswith (o->name, ".ctors")
+ || startswith (o->name, ".dtors"))
&& !o->gc_mark)
{
if (!_bfd_coff_gc_mark (info, o, _bfd_coff_gc_mark_hook))
bfd_boolean
_bfd_coff_close_and_cleanup (bfd *abfd)
{
- if (abfd->format == bfd_object
- && bfd_family_coff (abfd)
- && coff_data (abfd) != NULL)
+ struct coff_tdata *tdata = coff_data (abfd);
+
+ if (tdata != NULL)
{
/* PR 25447:
Do not clear the keep_syms and keep_strings flags.
These may have been set by pe_ILF_build_a_bfd() indicating
that the syms and strings pointers are not to be freed. */
- if (!_bfd_coff_free_symbols (abfd))
+ if (bfd_get_format (abfd) == bfd_object
+ && bfd_family_coff (abfd)
+ && !_bfd_coff_free_symbols (abfd))
return FALSE;
+
+ if (bfd_get_format (abfd) == bfd_object
+ || bfd_get_format (abfd) == bfd_core)
+ _bfd_dwarf2_cleanup_debug_info (abfd, &tdata->dwarf2_find_line_info);
}
return _bfd_generic_close_and_cleanup (abfd);
}