+2020-03-02 Alan Modra <amodra@gmail.com>
+
+ * targets.c (bfd_cleanup): New typedef.
+ (struct bfd <_bfd_check_format>): Return a bfd_cleanup.
+ * libbfd-in.h (_bfd_no_cleanup): Define.
+ * format.c (bfd_reinit): Add cleanup parameter, call it.
+ (bfd_check_format_matches): Set cleanup from _bfd_check_format
+ call and pass to bfd_reinit. Delete temp, use abfd->xvec instead.
+ * aout-target.h (callback, object_p): Return bfd_cleanup.
+ * aout-tic30.c (tic30_aout_callback, tic30_aout_object_p): Likewise.
+ * archive.c (bfd_generic_archive_p): Likewise.
+ * binary.c (binary_object_p): Likewise.
+ * coff-alpha.c (alpha_ecoff_object_p): Likewise.
+ * coff-ia64.c (ia64coff_object_p): Likewise.
+ * coff-rs6000.c (_bfd_xcoff_archive_p, rs6000coff_core_p): Likewise.
+ * coff-sh.c (coff_small_object_p): Likewise.
+ * coff-stgo32.c (go32_check_format): Likewise.
+ * coff64-rs6000.c (xcoff64_archive_p, rs6000coff_core_p),
+ (xcoff64_core_p): Likewise.
+ * coffgen.c (coff_real_object_p, coff_object_p): Likewise.
+ * elf-bfd.h (bfd_elf32_object_p, bfd_elf32_core_file_p),
+ (bfd_elf64_object_p, bfd_elf64_core_file_p): Likewise.
+ * elfcode.h (elf_object_p): Likewise.
+ * elfcore.h (elf_core_file_p): Likewise.
+ * i386msdos.c (msdos_object_p): Likewise.
+ * ihex.c (ihex_object_p): Likewise.
+ * libaout.h (some_aout_object_p): Likewise.
+ * libbfd-in.h (bfd_generic_archive_p, _bfd_dummy_target),
+ (_bfd_vms_lib_alpha_archive_p, _bfd_vms_lib_ia64_archive_p): Likewise.
+ * libbfd.c (_bfd_dummy_target): Likewise.
+ * libcoff-in.h (coff_object_p): Likewise.
+ * mach-o-aarch64.c (bfd_mach_o_arm64_object_p),
+ (bfd_mach_o_arm64_core_p): Likewise.
+ * mach-o-arm.c (bfd_mach_o_arm_object_p),
+ (bfd_mach_o_arm_core_p): Likewise.
+ * mach-o-i386.c (bfd_mach_o_i386_object_p),
+ (bfd_mach_o_i386_core_p): Likewise.
+ * mach-o-x86-64.c (bfd_mach_o_x86_64_object_p),
+ (bfd_mach_o_x86_64_core_p): Likewise.
+ * mach-o.c (bfd_mach_o_header_p, bfd_mach_o_gen_object_p),
+ (bfd_mach_o_gen_core_p, bfd_mach_o_fat_archive_p): Likewise.
+ * mach-o.h (bfd_mach_o_object_p, bfd_mach_o_core_p),
+ (bfd_mach_o_fat_archive_p, bfd_mach_o_header_p): Likewise.
+ * mmo.c (mmo_object_p): Likewise.
+ * pef.c (bfd_pef_object_p, bfd_pef_xlib_object_p): Likewise.
+ * peicode.h (coff_real_object_p, pe_ILF_object_p),
+ (pe_bfd_object_p): Likewise.
+ * plugin.c (ld_plugin_object_p, bfd_plugin_object_p): Likewise.
+ * ppcboot.c (ppcboot_object_p): Likewise.
+ * rs6000-core.c (rs6000coff_core_p): Likewise.
+ * som.c (som_object_setup, som_object_p): Likewise.
+ * srec.c (srec_object_p, symbolsrec_object_p): Likewise.
+ * tekhex.c (tekhex_object_p): Likewise.
+ * vms-alpha.c (alpha_vms_object_p): Likewise.
+ * vms-lib.c (_bfd_vms_lib_archive_p, _bfd_vms_lib_alpha_archive_p),
+ (_bfd_vms_lib_ia64_archive_p, _bfd_vms_lib_txt_archive_p): Likewise.
+ * wasm-module.c (wasm_object_p): Likewise.
+ * xsym.c (bfd_sym_object_p): Likewise.
+ * xsym.h (bfd_sym_object_p): Likewise.
+ * aoutx.h (some_aout_object_p): Likewise, and callback parameter
+ return type.
+ * pdp11.c (some_aout_object_p): Likewise.
+ * plugin.c (register_ld_plugin_object_p): Update object_p
+ parameter type.
+ * plugin.h (register_ld_plugin_object_p): Likewise.
+ * bfd-in2.h: Regenerate.
+ * libbfd.h: Regenerate.
+ * libcoff.h: Regenerate.
+
2020-03-02 Alan Modra <amodra@gmail.com>
* coff-alpha.c (alpha_ecoff_le_vec): Add SEC_SMALL_DATA to
This routine is called from some_aout_object_p just before it returns. */
#ifndef MY_callback
-static const bfd_target *
+static bfd_cleanup
MY (callback) (bfd *abfd)
{
struct internal_exec *execp = exec_hdr (abfd);
/* Don't set sizes now -- can't be sure until we know arch & mach.
Sizes get set in set_sizes callback, later. */
- return abfd->xvec;
+ return _bfd_no_cleanup;
}
#endif
#ifndef MY_object_p
/* Finish up the reading of an a.out file header. */
-static const bfd_target *
+static bfd_cleanup
MY (object_p) (bfd *abfd)
{
struct external_exec exec_bytes; /* Raw exec header from file. */
struct internal_exec exec; /* Cleaned-up exec header. */
- const bfd_target *target;
+ bfd_cleanup cleanup;
size_t amt = EXEC_BYTES_SIZE;
if (bfd_bread ((void *) &exec_bytes, amt, abfd) != amt)
exec.a_info = SWAP_MAGIC (exec_bytes.e_info);
#endif
- target = NAME (aout, some_aout_object_p) (abfd, &exec, MY (callback));
+ cleanup = NAME (aout, some_aout_object_p) (abfd, &exec, MY (callback));
#ifdef ENTRY_CAN_BE_ZERO
/* The NEWSOS3 entry-point is/was 0, which (amongst other lossage)
}
#endif /* ENTRY_CAN_BE_ZERO */
- return target;
+ return cleanup;
}
#define MY_object_p MY (object_p)
#endif
/* Set parameters about this a.out file that are machine-dependent.
This routine is called from some_aout_object_p just before it returns. */
-static const bfd_target *
+static bfd_cleanup
tic30_aout_callback (bfd *abfd)
{
struct internal_exec *execp = exec_hdr (abfd);
obj_datasec (abfd)->alignment_power = arch_align_power;
obj_bsssec (abfd)->alignment_power = arch_align_power;
}
- return abfd->xvec;
+ return _bfd_no_cleanup;
}
static bfd_reloc_status_type
/* Finish up the reading of an a.out file header. */
-static const bfd_target *
+static bfd_cleanup
tic30_aout_object_p (bfd *abfd)
{
struct external_exec exec_bytes; /* Raw exec header from file. */
struct internal_exec exec; /* Cleaned-up exec header. */
- const bfd_target *target;
+ bfd_cleanup cleanup;
size_t amt = EXEC_BYTES_SIZE;
if (bfd_bread (& exec_bytes, amt, abfd) != amt)
exec.a_info = SWAP_MAGIC (exec_bytes.e_info);
#endif
- target = NAME (aout, some_aout_object_p) (abfd, &exec, tic30_aout_callback);
+ cleanup = NAME (aout, some_aout_object_p) (abfd, &exec, tic30_aout_callback);
#ifdef ENTRY_CAN_BE_ZERO
/* The NEWSOS3 entry-point is/was 0, which (amongst other lossage)
}
#endif
- return target;
+ return cleanup;
}
/* Copy private section data. This actually does nothing with the
handle any last-minute setup.
*/
-const bfd_target *
+bfd_cleanup
NAME (aout, some_aout_object_p) (bfd *abfd,
struct internal_exec *execp,
- const bfd_target *(*callback_to_real_object_p) (bfd *))
+ bfd_cleanup (*callback_to_real_object_p) (bfd *))
{
struct aout_data_struct *rawptr, *oldrawptr;
- const bfd_target *result;
+ bfd_cleanup result;
size_t amt = sizeof (* rawptr);
rawptr = (struct aout_data_struct *) bfd_zalloc (abfd, amt);
adata (abfd)->segment_size = SEGMENT_SIZE;
adata (abfd)->exec_bytes_size = EXEC_BYTES_SIZE;
- return abfd->xvec;
+ return _bfd_no_cleanup
/* The architecture is encoded in various ways in various a.out variants,
or is not encoded at all in some of them. The relocation size depends
return (bfd *) _bfd_ptr_bfd_null_error (archive);
}
-const bfd_target *
+bfd_cleanup
bfd_generic_archive_p (bfd *abfd)
{
struct artdata *tdata_hold;
}
}
- return abfd->xvec;
+ return _bfd_no_cleanup;
}
/* Some constants for a 32 bit BSD archive structure. We do not
/* Forward declaration. */
typedef struct flag_info flag_info;
+typedef void (*bfd_cleanup) (bfd *);
+
typedef struct bfd_target
{
/* Identifies the kind of target, e.g., SunOS4, Ultrix, etc. */
/* Format dependent routines: these are vectors of entry points
within the target vector structure, one for each format to check. */
- /* Check the format of a file being read. Return a <<bfd_target *>> or zero. */
- const struct bfd_target *
- (*_bfd_check_format[bfd_type_end]) (bfd *);
+ /* Check the format of a file being read. Return a <<bfd_cleanup>> on
+ success or zero on failure. */
+ bfd_cleanup (*_bfd_check_format[bfd_type_end]) (bfd *);
/* Set the format of a file being written. */
bfd_boolean (*_bfd_set_format[bfd_type_end]) (bfd *);
was not defaulted. That is, it must be explicitly specified as
being binary. */
-static const bfd_target *
+static bfd_cleanup
binary_object_p (bfd *abfd)
{
struct stat statbuf;
abfd->tdata.any = (void *) sec;
- return abfd->xvec;
+ return _bfd_no_cleanup;
}
#define binary_close_and_cleanup _bfd_generic_close_and_cleanup
\f
/* Recognize an Alpha ECOFF file. */
-static const bfd_target *
+static bfd_cleanup
alpha_ecoff_object_p (bfd *abfd)
{
- static const bfd_target *ret;
+ bfd_cleanup ret;
ret = coff_object_p (abfd);
#include "coffcode.h"
-static const bfd_target *
+static bfd_cleanup
ia64coff_object_p (bfd *abfd)
{
#ifdef COFF_IMAGE_WITH_PE
extern reloc_howto_type *_bfd_xcoff_reloc_type_lookup
(bfd *, bfd_reloc_code_real_type);
extern bfd_boolean _bfd_xcoff_slurp_armap (bfd *);
-extern const bfd_target *_bfd_xcoff_archive_p (bfd *);
+extern bfd_cleanup _bfd_xcoff_archive_p (bfd *);
extern void * _bfd_xcoff_read_ar_hdr (bfd *);
extern bfd *_bfd_xcoff_openr_next_archived_file (bfd *, bfd *);
extern int _bfd_xcoff_stat_arch_elt (bfd *, struct stat *);
#define coff_mkobject _bfd_xcoff_mkobject
#define coff_bfd_is_local_label_name _bfd_xcoff_is_local_label_name
#ifdef AIX_CORE
-extern const bfd_target * rs6000coff_core_p (bfd *abfd);
+extern bfd_cleanup rs6000coff_core_p (bfd *abfd);
extern bfd_boolean rs6000coff_core_file_matches_executable_p
(bfd *cbfd, bfd *ebfd);
extern char *rs6000coff_core_file_failing_command (bfd *abfd);
/* See if this is an XCOFF archive. */
-const bfd_target *
+bfd_cleanup
_bfd_xcoff_archive_p (bfd *abfd)
{
struct artdata *tdata_hold;
return NULL;
}
- return abfd->xvec;
+ return _bfd_no_cleanup;
}
/* Read the archive header in an XCOFF archive. */
/* Only recognize the small versions if the target was not defaulted.
Otherwise we won't recognize the non default endianness. */
-static const bfd_target *
+static bfd_cleanup
coff_small_object_p (bfd *abfd)
{
if (abfd->target_defaulted)
#define COFF_ADJUST_AUX_OUT_PRE adjust_aux_out_pre
#define COFF_ADJUST_AUX_OUT_POST adjust_aux_out_post
-static const bfd_target *go32_check_format (bfd *);
+static bfd_cleanup go32_check_format (bfd *);
#define COFF_CHECK_FORMAT go32_check_format
/* coff_object_p only checks 2 bytes F_MAGIC at GO32_STUBSIZE inside the file
which is too fragile. */
-static const bfd_target *
+static bfd_cleanup
go32_check_format (bfd *abfd)
{
char mz[2];
asection **);
static bfd_boolean xcoff64_slurp_armap
(bfd *);
-static const bfd_target *xcoff64_archive_p
+static bfd_cleanup xcoff64_archive_p
(bfd *);
static bfd *xcoff64_openr_next_archived_file
(bfd *, bfd *);
#define coff_bfd_reloc_type_lookup xcoff64_reloc_type_lookup
#define coff_bfd_reloc_name_lookup xcoff64_reloc_name_lookup
#ifdef AIX_CORE
-extern const bfd_target * rs6000coff_core_p
+extern bfd_cleanup rs6000coff_core_p
(bfd *abfd);
extern bfd_boolean rs6000coff_core_file_matches_executable_p
(bfd *cbfd, bfd *ebfd);
/* See if this is an NEW XCOFF archive. */
-static const bfd_target *
+static bfd_cleanup
xcoff64_archive_p (bfd *abfd)
{
struct artdata *tdata_hold;
return NULL;
}
- return abfd->xvec;
+ return _bfd_no_cleanup;
}
&bfd_xcoff_backend_data,
};
-extern const bfd_target *xcoff64_core_p
+extern bfd_cleanup xcoff64_core_p
(bfd *);
extern bfd_boolean xcoff64_core_file_matches_executable_p
(bfd *, bfd *);
/* Read in a COFF object and make it into a BFD. This is used by
ECOFF as well. */
-const bfd_target *
+bfd_cleanup
coff_real_object_p (bfd *,
unsigned,
struct internal_filehdr *,
struct internal_aouthdr *);
-const bfd_target *
+bfd_cleanup
coff_real_object_p (bfd *abfd,
unsigned nscns,
struct internal_filehdr *internal_f,
}
_bfd_coff_free_symbols (abfd);
- return abfd->xvec;
+ return _bfd_no_cleanup;
fail:
_bfd_coff_free_symbols (abfd);
abfd->tdata.any = tdata_save;
abfd->flags = oflags;
abfd->start_address = ostart;
- return (const bfd_target *) NULL;
+ return NULL;
}
/* Turn a COFF file into a BFD, but fail with bfd_error_wrong_format if it is
not a COFF file. This is also used by ECOFF. */
-const bfd_target *
+bfd_cleanup
coff_object_p (bfd *abfd)
{
bfd_size_type filhsz;
extern bfd_boolean _bfd_elf_final_write_processing (bfd *);
-extern const bfd_target *bfd_elf32_object_p
+extern bfd_cleanup bfd_elf32_object_p
(bfd *);
-extern const bfd_target *bfd_elf32_core_file_p
+extern bfd_cleanup bfd_elf32_core_file_p
(bfd *);
extern char *bfd_elf32_core_file_failing_command
(bfd *);
extern bfd_boolean bfd_elf32_slurp_reloc_table
(bfd *, asection *, asymbol **, bfd_boolean);
-extern const bfd_target *bfd_elf64_object_p
+extern bfd_cleanup bfd_elf64_object_p
(bfd *);
-extern const bfd_target *bfd_elf64_core_file_p
+extern bfd_cleanup bfd_elf64_core_file_p
(bfd *);
extern char *bfd_elf64_core_file_failing_command
(bfd *);
any side effects in ABFD, or any data it points to (like tdata), if the
file does not match the target vector. */
-const bfd_target *
+bfd_cleanup
elf_object_p (bfd *abfd)
{
Elf_External_Ehdr x_ehdr; /* Elf file header, external form */
s->flags |= SEC_DEBUGGING;
}
}
- return target;
+ return _bfd_no_cleanup;
got_wrong_format_error:
bfd_set_error (bfd_error_wrong_format);
that allow standard bfd access to the general registers (.reg) and the
floating point registers (.reg2). */
-const bfd_target *
+bfd_cleanup
elf_core_file_p (bfd *abfd)
{
Elf_External_Ehdr x_ehdr; /* Elf file header, external form. */
/* Save the entry point from the ELF header. */
abfd->start_address = i_ehdrp->e_entry;
- return abfd->xvec;
+ return _bfd_no_cleanup;
wrong:
bfd_set_error (bfd_error_wrong_format);
/* Clear out a subset of BFD state. */
static void
-bfd_reinit (bfd *abfd, unsigned int section_id)
+bfd_reinit (bfd *abfd, unsigned int section_id, bfd_cleanup cleanup)
{
+ _bfd_section_id = section_id;
+ if (cleanup)
+ cleanup (abfd);
abfd->tdata.any = NULL;
abfd->arch_info = &bfd_default_arch_struct;
abfd->flags &= BFD_FLAGS_SAVED;
bfd_section_list_clear (abfd);
- _bfd_section_id = section_id;
}
/* Restores bfd state saved by bfd_preserve_save. */
int ar_match_index;
unsigned int initial_section_id = _bfd_section_id;
struct bfd_preserve preserve, preserve_match;
+ bfd_cleanup cleanup = NULL;
if (matching != NULL)
*matching = NULL;
if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0) /* rewind! */
goto err_ret;
- right_targ = BFD_SEND_FMT (abfd, _bfd_check_format, (abfd));
+ cleanup = BFD_SEND_FMT (abfd, _bfd_check_format, (abfd));
- if (right_targ)
+ if (cleanup)
goto ok_ret;
/* For a long time the code has dropped through to check all
for (target = bfd_target_vector; *target != NULL; target++)
{
- const bfd_target *temp;
void **high_water;
/* The binary target matches anything, so don't return it when
/* If we already tried a match, the bfd is modified and may
have sections attached, which will confuse the next
_bfd_check_format call. */
- bfd_reinit (abfd, initial_section_id);
+ bfd_reinit (abfd, initial_section_id, cleanup);
/* Free bfd_alloc memory too. If we have matched and preserved
a target then the high water mark is that much higher. */
if (preserve_match.marker)
if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
goto err_ret;
- temp = BFD_SEND_FMT (abfd, _bfd_check_format, (abfd));
- if (temp)
+ cleanup = BFD_SEND_FMT (abfd, _bfd_check_format, (abfd));
+ if (cleanup)
{
- int match_priority = temp->match_priority;
+ int match_priority = abfd->xvec->match_priority;
#if BFD_SUPPORTS_PLUGINS
/* If this object can be handled by a plugin, give that the
lowest priority; objects both handled by a plugin and
/* If this is the default target, accept it, even if
other targets might match. People who want those
other targets have to set the GNUTARGET variable. */
- if (temp == bfd_default_vector[0])
+ if (abfd->xvec == bfd_default_vector[0])
goto ok_ret;
if (matching_vector)
- matching_vector[match_count] = temp;
+ matching_vector[match_count] = abfd->xvec;
match_count++;
if (match_priority < best_match)
if (match_priority <= best_match)
{
/* This format checks out as ok! */
- right_targ = temp;
+ right_targ = abfd->xvec;
best_count++;
}
}
if (preserve_match.marker == NULL)
{
- match_targ = temp;
+ match_targ = abfd->xvec;
if (!bfd_preserve_save (abfd, &preserve_match))
goto err_ret;
}
RIGHT_TARG again. */
if (match_targ != right_targ)
{
- bfd_reinit (abfd, initial_section_id);
+ bfd_reinit (abfd, initial_section_id, cleanup);
bfd_release (abfd, preserve.marker);
if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
goto err_ret;
- match_targ = BFD_SEND_FMT (abfd, _bfd_check_format, (abfd));
- BFD_ASSERT (match_targ != NULL);
+ cleanup = BFD_SEND_FMT (abfd, _bfd_check_format, (abfd));
+ BFD_ASSERT (cleanup != NULL);
}
ok_ret:
return aout_32_mkobject (abfd);
}
-static const bfd_target *
+static bfd_cleanup
msdos_object_p (bfd *abfd)
{
struct external_DOS_hdr hdr;
bfd_set_section_size (section, size);
section->alignment_power = 4;
- return abfd->xvec;
+ return _bfd_no_cleanup;
}
static int
/* Try to recognize an Intel Hex file. */
-static const bfd_target *
+static bfd_cleanup
ihex_object_p (bfd *abfd)
{
void * tdata_save;
return NULL;
}
- return abfd->xvec;
+ return _bfd_no_cleanup;
}
/* Read the contents of a section in an Intel Hex file. */
extern bfd_boolean NAME (aout, make_sections)
(bfd *);
-extern const bfd_target * NAME (aout, some_aout_object_p)
- (bfd *, struct internal_exec *, const bfd_target *(*) (bfd *));
+extern bfd_cleanup NAME (aout, some_aout_object_p)
+ (bfd *, struct internal_exec *, bfd_cleanup (*) (bfd *));
extern bfd_boolean NAME (aout, mkobject)
(bfd *);
(bfd *) ATTRIBUTE_HIDDEN;
extern char *_bfd_append_relative_path
(bfd *, char *) ATTRIBUTE_HIDDEN;
-extern const bfd_target *bfd_generic_archive_p
+extern bfd_cleanup bfd_generic_archive_p
(bfd *) ATTRIBUTE_HIDDEN;
extern bfd_boolean bfd_slurp_armap
(bfd *) ATTRIBUTE_HIDDEN;
extern bfd *_bfd_new_bfd_contained_in
(bfd *) ATTRIBUTE_HIDDEN;
-extern const bfd_target *_bfd_dummy_target
+extern bfd_cleanup _bfd_dummy_target
(bfd *) ATTRIBUTE_HIDDEN;
+#define _bfd_no_cleanup _bfd_void_bfd
extern void bfd_dont_truncate_arname
(bfd *, const char *, char *) ATTRIBUTE_HIDDEN;
(bfd *, const char *) ATTRIBUTE_HIDDEN;
extern bfd *_bfd_vms_lib_get_imagelib_file
(bfd *) ATTRIBUTE_HIDDEN;
-extern const bfd_target *_bfd_vms_lib_alpha_archive_p
+extern bfd_cleanup _bfd_vms_lib_alpha_archive_p
(bfd *) ATTRIBUTE_HIDDEN;
-extern const bfd_target *_bfd_vms_lib_ia64_archive_p
+extern bfd_cleanup _bfd_vms_lib_ia64_archive_p
(bfd *) ATTRIBUTE_HIDDEN;
extern bfd_boolean _bfd_vms_lib_alpha_mkarchive
(bfd *) ATTRIBUTE_HIDDEN;
return 0;
}
-const bfd_target *
+bfd_cleanup
_bfd_dummy_target (bfd *ignore_abfd ATTRIBUTE_UNUSED)
{
bfd_set_error (bfd_error_wrong_format);
(bfd *) ATTRIBUTE_HIDDEN;
extern char *_bfd_append_relative_path
(bfd *, char *) ATTRIBUTE_HIDDEN;
-extern const bfd_target *bfd_generic_archive_p
+extern bfd_cleanup bfd_generic_archive_p
(bfd *) ATTRIBUTE_HIDDEN;
extern bfd_boolean bfd_slurp_armap
(bfd *) ATTRIBUTE_HIDDEN;
extern bfd *_bfd_new_bfd_contained_in
(bfd *) ATTRIBUTE_HIDDEN;
-extern const bfd_target *_bfd_dummy_target
+extern bfd_cleanup _bfd_dummy_target
(bfd *) ATTRIBUTE_HIDDEN;
+#define _bfd_no_cleanup _bfd_void_bfd
extern void bfd_dont_truncate_arname
(bfd *, const char *, char *) ATTRIBUTE_HIDDEN;
(bfd *, const char *) ATTRIBUTE_HIDDEN;
extern bfd *_bfd_vms_lib_get_imagelib_file
(bfd *) ATTRIBUTE_HIDDEN;
-extern const bfd_target *_bfd_vms_lib_alpha_archive_p
+extern bfd_cleanup _bfd_vms_lib_alpha_archive_p
(bfd *) ATTRIBUTE_HIDDEN;
-extern const bfd_target *_bfd_vms_lib_ia64_archive_p
+extern bfd_cleanup _bfd_vms_lib_ia64_archive_p
(bfd *) ATTRIBUTE_HIDDEN;
extern bfd_boolean _bfd_vms_lib_alpha_mkarchive
(bfd *) ATTRIBUTE_HIDDEN;
#define coff_hash_table(p) ((struct coff_link_hash_table *) ((p)->hash))
/* Functions in coffgen.c. */
-extern const bfd_target *coff_object_p
+extern bfd_cleanup coff_object_p
(bfd *);
extern struct bfd_section *coff_section_from_bfd_index
(bfd *, int);
#define coff_hash_table(p) ((struct coff_link_hash_table *) ((p)->hash))
/* Functions in coffgen.c. */
-extern const bfd_target *coff_object_p
+extern bfd_cleanup coff_object_p
(bfd *);
extern struct bfd_section *coff_section_from_bfd_index
(bfd *, int);
#define bfd_mach_o_tgt_seg_table NULL
#define bfd_mach_o_section_type_valid_for_tgt NULL
-static const bfd_target *
+static bfd_cleanup
bfd_mach_o_arm64_object_p (bfd *abfd)
{
return bfd_mach_o_header_p (abfd, 0, 0, BFD_MACH_O_CPU_TYPE_ARM64);
}
-static const bfd_target *
+static bfd_cleanup
bfd_mach_o_arm64_core_p (bfd *abfd)
{
return bfd_mach_o_header_p (abfd, 0,
#define bfd_mach_o_tgt_seg_table NULL
#define bfd_mach_o_section_type_valid_for_tgt NULL
-static const bfd_target *
+static bfd_cleanup
bfd_mach_o_arm_object_p (bfd *abfd)
{
return bfd_mach_o_header_p (abfd, 0, 0, BFD_MACH_O_CPU_TYPE_ARM);
}
-static const bfd_target *
+static bfd_cleanup
bfd_mach_o_arm_core_p (bfd *abfd)
{
return bfd_mach_o_header_p (abfd, 0,
#define bfd_mach_o_core_p bfd_mach_o_i386_core_p
#define bfd_mach_o_mkobject bfd_mach_o_i386_mkobject
-static const bfd_target *
+static bfd_cleanup
bfd_mach_o_i386_object_p (bfd *abfd)
{
return bfd_mach_o_header_p (abfd, 0, 0, BFD_MACH_O_CPU_TYPE_I386);
}
-static const bfd_target *
+static bfd_cleanup
bfd_mach_o_i386_core_p (bfd *abfd)
{
return bfd_mach_o_header_p (abfd, 0,
#define bfd_mach_o_core_p bfd_mach_o_x86_64_core_p
#define bfd_mach_o_mkobject bfd_mach_o_x86_64_mkobject
-static const bfd_target *
+static bfd_cleanup
bfd_mach_o_x86_64_object_p (bfd *abfd)
{
return bfd_mach_o_header_p (abfd, 0, 0, BFD_MACH_O_CPU_TYPE_X86_64);
}
-static const bfd_target *
+static bfd_cleanup
bfd_mach_o_x86_64_core_p (bfd *abfd)
{
return bfd_mach_o_header_p (abfd, 0,
return TRUE;
}
-const bfd_target *
+bfd_cleanup
bfd_mach_o_header_p (bfd *abfd,
file_ptr hdr_off,
bfd_mach_o_filetype file_type,
if (!bfd_mach_o_scan (abfd, &header, mdata))
goto wrong;
- return abfd->xvec;
+ return _bfd_no_cleanup;
wrong:
bfd_set_error (bfd_error_wrong_format);
return NULL;
}
-static const bfd_target *
+static bfd_cleanup
bfd_mach_o_gen_object_p (bfd *abfd)
{
return bfd_mach_o_header_p (abfd, 0, 0, 0);
}
-static const bfd_target *
+static bfd_cleanup
bfd_mach_o_gen_core_p (bfd *abfd)
{
return bfd_mach_o_header_p (abfd, 0, BFD_MACH_O_MH_CORE, 0);
mach_o_fat_archentry *archentries;
} mach_o_fat_data_struct;
-const bfd_target *
+bfd_cleanup
bfd_mach_o_fat_archive_p (bfd *abfd)
{
mach_o_fat_data_struct *adata = NULL;
abfd->tdata.mach_o_fat_data = adata;
- return abfd->xvec;
+ return _bfd_no_cleanup;
error:
if (adata != NULL)
bfd_boolean bfd_mach_o_valid (bfd *);
bfd_boolean bfd_mach_o_mkobject_init (bfd *);
-const bfd_target *bfd_mach_o_object_p (bfd *);
-const bfd_target *bfd_mach_o_core_p (bfd *);
-const bfd_target *bfd_mach_o_fat_archive_p (bfd *);
+bfd_cleanup bfd_mach_o_object_p (bfd *);
+bfd_cleanup bfd_mach_o_core_p (bfd *);
+bfd_cleanup bfd_mach_o_fat_archive_p (bfd *);
bfd *bfd_mach_o_fat_openr_next_archived_file (bfd *, bfd *);
bfd_boolean bfd_mach_o_set_arch_mach (bfd *, enum bfd_architecture,
unsigned long);
int bfd_mach_o_core_file_failing_signal (bfd *);
bfd_boolean bfd_mach_o_core_file_matches_executable_p (bfd *, bfd *);
bfd *bfd_mach_o_fat_extract (bfd *, bfd_format , const bfd_arch_info_type *);
-const bfd_target *bfd_mach_o_header_p (bfd *, file_ptr, bfd_mach_o_filetype,
- bfd_mach_o_cpu_type);
+bfd_cleanup bfd_mach_o_header_p (bfd *, file_ptr, bfd_mach_o_filetype,
+ bfd_mach_o_cpu_type);
bfd_boolean bfd_mach_o_build_commands (bfd *);
bfd_boolean bfd_mach_o_set_section_contents (bfd *, asection *, const void *,
file_ptr, bfd_size_type);
static void mmo_xore_64 (asection *, bfd_vma vma, bfd_vma value);
static void mmo_xore_32 (asection *, bfd_vma vma, unsigned int);
static void mmo_xore_16 (asection *, bfd_vma vma, unsigned int);
-static const bfd_target *mmo_object_p (bfd *);
+static bfd_cleanup mmo_object_p (bfd *);
static void mmo_map_set_sizes (bfd *, asection *, void *);
static bfd_boolean mmo_get_symbols (bfd *);
static bfd_boolean mmo_create_symbol (bfd *, const char *, bfd_vma,
/* Check whether an existing file is an mmo file. */
-static const bfd_target *
+static bfd_cleanup
mmo_object_p (bfd *abfd)
{
struct stat statbuf;
if (! bfd_default_set_arch_mach (abfd, bfd_arch_mmix, 0))
goto bad_format_free;
- return abfd->xvec;
+ return _bfd_no_cleanup;
bad_format_free:
free (abfd->tdata.mmo_data->lop_stab_symbol);
environment's "finish up" function just before returning, to
handle any last-minute setup. */
-const bfd_target *
+bfd_cleanup
NAME (aout, some_aout_object_p) (bfd *abfd,
struct internal_exec *execp,
- const bfd_target *(*callback_to_real_object_p) (bfd *))
+ bfd_cleanup (*callback_to_real_object_p) (bfd *))
{
struct aout_data_struct *rawptr, *oldrawptr;
- const bfd_target *result;
+ bfd_cleanup cleanup;
size_t amt = sizeof (struct aout_data_struct);
rawptr = bfd_zalloc (abfd, amt);
adata(abfd)->segment_size = SEGMENT_SIZE;
adata(abfd)->exec_bytes_size = EXEC_BYTES_SIZE;
- return abfd->xvec;
+ return _bfd_no_cleanup;
/* The architecture is encoded in various ways in various a.out variants,
or is not encoded at all in some of them. The relocation size depends
header, should cope with them in this callback as well. */
#endif /* DOCUMENTATION */
- result = (*callback_to_real_object_p)(abfd);
+ cleanup = (*callback_to_real_object_p)(abfd);
/* Now that the segment addresses have been worked out, take a better
guess at whether the file is executable. If the entry point
}
#endif /* STAT_FOR_EXEC */
- if (!result)
+ if (!cleanup)
{
free (rawptr);
abfd->tdata.aout_data = oldrawptr;
}
- return result;
+ return cleanup;
}
/* Initialize ABFD for use with a.out files. */
return 0;
}
-static const bfd_target *
+static bfd_cleanup
bfd_pef_object_p (bfd *abfd)
{
bfd_pef_header header;
if (bfd_pef_scan (abfd, &header, mdata))
goto wrong;
- return abfd->xvec;
+ return _bfd_no_cleanup;
wrong:
bfd_set_error (bfd_error_wrong_format);
return 0;
}
-static const bfd_target *
+static bfd_cleanup
bfd_pef_xlib_object_p (bfd *abfd)
{
bfd_pef_xlib_header header;
return NULL;
}
- return abfd->xvec;
+ return _bfd_no_cleanup;
}
const bfd_target pef_xlib_vec =
pe_ILF_vars;
#endif /* COFF_IMAGE_WITH_PE */
-const bfd_target *coff_real_object_p
+bfd_cleanup coff_real_object_p
(bfd *, unsigned, struct internal_filehdr *, struct internal_aouthdr *);
\f
#ifndef NO_COFF_RELOCS
/* We have detected a Image Library Format archive element.
Decode the element and return the appropriate target. */
-static const bfd_target *
+static bfd_cleanup
pe_ILF_object_p (bfd * abfd)
{
bfd_byte buffer[14];
return NULL;
}
- return abfd->xvec;
+ return _bfd_no_cleanup;
}
static void
free (data);
}
-static const bfd_target *
+static bfd_cleanup
pe_bfd_object_p (bfd * abfd)
{
bfd_byte buffer[6];
struct internal_aouthdr internal_a;
bfd_size_type opt_hdr_size;
file_ptr offset;
- const bfd_target *result;
+ bfd_cleanup result;
/* Detect if this a Microsoft Import Library Format element. */
/* First read the beginning of the header. */
/* There may be plugin libraries in lib/bfd-plugins. */
static int has_plugin_list = -1;
-static const bfd_target *(*ld_plugin_object_p) (bfd *);
+static bfd_cleanup (*ld_plugin_object_p) (bfd *);
static const char *plugin_name;
/* Register OBJECT_P to be used by bfd_plugin_object_p. */
void
-register_ld_plugin_object_p (const bfd_target *(*object_p) (bfd *))
+register_ld_plugin_object_p (bfd_cleanup (*object_p) (bfd *))
{
ld_plugin_object_p = object_p;
}
}
-static const bfd_target *
+static bfd_cleanup
bfd_plugin_object_p (bfd *abfd)
{
if (ld_plugin_object_p)
if (abfd->plugin_format == bfd_plugin_unknown && !load_plugin (abfd))
return NULL;
- return abfd->plugin_format == bfd_plugin_yes ? abfd->xvec : NULL;
+ return abfd->plugin_format == bfd_plugin_yes ? _bfd_no_cleanup : NULL;
}
/* Copy any private info we understand from the input bfd
bfd_boolean bfd_plugin_target_p (const bfd_target *);
bfd_boolean bfd_plugin_specified_p (void);
bfd_boolean bfd_link_plugin_object_p (bfd *);
-void register_ld_plugin_object_p (const bfd_target *(*object_p) (bfd *));
+void register_ld_plugin_object_p (bfd_cleanup (*object_p) (bfd *));
typedef struct plugin_data_struct
{
was not defaulted. That is, it must be explicitly specified as
being ppcboot. */
-static const bfd_target *
+static bfd_cleanup
ppcboot_object_p (bfd *abfd)
{
struct stat statbuf;
memcpy (&tdata->header, &hdr, sizeof (ppcboot_hdr_t));
ppcboot_set_arch_mach (abfd, bfd_arch_powerpc, 0L);
- return abfd->xvec;
+ return _bfd_no_cleanup;
}
#define ppcboot_close_and_cleanup _bfd_generic_close_and_cleanup
/* Define prototypes for certain functions, to avoid a compiler warning
saying that they are missing. */
-const bfd_target * rs6000coff_core_p (bfd *abfd);
+const bfd_cleanup rs6000coff_core_p (bfd *abfd);
bfd_boolean rs6000coff_core_file_matches_executable_p (bfd *core_bfd,
bfd *exec_bfd);
char * rs6000coff_core_file_failing_command (bfd *abfd);
/* Decide if a given bfd represents a `core' file or not. There really is no
magic number or anything like, in rs6000coff. */
-const bfd_target *
+bfd_cleanup
rs6000coff_core_p (bfd *abfd)
{
CoreHdr core;
}
#endif
- return abfd->xvec; /* This is garbage for now. */
+ return _bfd_no_cleanup;
fail:
bfd_release (abfd, abfd->tdata.any);
/* Perform some initialization for an object. Save results of this
initialization in the BFD. */
-static const bfd_target *
+static bfd_cleanup
som_object_setup (bfd *abfd,
struct som_header *file_hdrp,
struct som_exec_auxhdr *aux_hdrp,
+ current_offset);
obj_som_exec_data (abfd)->system_id = file_hdrp->system_id;
- return abfd->xvec;
+ return _bfd_no_cleanup;
}
/* Convert all of the space and subspace info into BFD sections. Each space
/* Read in a SOM object and make it into a BFD. */
-static const bfd_target *
+static bfd_cleanup
som_object_p (bfd *abfd)
{
struct som_external_header ext_file_hdr;
/* Check whether an existing file is an S-record file. */
-static const bfd_target *
+static bfd_cleanup
srec_object_p (bfd *abfd)
{
void * tdata_save;
if (abfd->symcount > 0)
abfd->flags |= HAS_SYMS;
- return abfd->xvec;
+ return _bfd_no_cleanup;
}
/* Check whether an existing file is an S-record file with symbols. */
-static const bfd_target *
+static bfd_cleanup
symbolsrec_object_p (bfd *abfd)
{
void * tdata_save;
if (abfd->symcount > 0)
abfd->flags |= HAS_SYMS;
- return abfd->xvec;
+ return _bfd_no_cleanup;
}
/* Read in the contents of a section in an S-record file. */
.{* Forward declaration. *}
.typedef struct flag_info flag_info;
.
+.typedef void (*bfd_cleanup) (bfd *);
+.
.typedef struct bfd_target
.{
. {* Identifies the kind of target, e.g., SunOS4, Ultrix, etc. *}
. {* Format dependent routines: these are vectors of entry points
. within the target vector structure, one for each format to check. *}
.
-. {* Check the format of a file being read. Return a <<bfd_target *>> or zero. *}
-. const struct bfd_target *
-. (*_bfd_check_format[bfd_type_end]) (bfd *);
+. {* Check the format of a file being read. Return a <<bfd_cleanup>> on
+. success or zero on failure. *}
+. bfd_cleanup (*_bfd_check_format[bfd_type_end]) (bfd *);
.
. {* Set the format of a file being written. *}
. bfd_boolean (*_bfd_set_format[bfd_type_end]) (bfd *);
/* Return TRUE if the file looks like it's in TekHex format. Just look
for a percent sign and some hex digits. */
-static const bfd_target *
+static bfd_cleanup
tekhex_object_p (bfd *abfd)
{
char b[4];
if (!pass_over (abfd, first_phase))
return NULL;
- return abfd->xvec;
+ return _bfd_no_cleanup;
}
static void
/* Check the format for a file being read.
Return a (bfd_target *) if it's an object file or zero if not. */
-static const struct bfd_target *
+static bfd_cleanup
alpha_vms_object_p (bfd *abfd)
{
void *tdata_save = abfd->tdata.any;
if (! bfd_default_set_arch_mach (abfd, bfd_arch_alpha, 0))
goto err_wrong_format;
- return abfd->xvec;
+ return alpha_vms_free_private;
err_wrong_format:
bfd_set_error (bfd_error_wrong_format);
/* Standard function. */
-static const bfd_target *
+static bfd_cleanup
_bfd_vms_lib_archive_p (bfd *abfd, enum vms_lib_kind kind)
{
struct vms_lhd lhd;
if (tdata->type == LBR__C_TYP_ESHSTB || tdata->type == LBR__C_TYP_ISHSTB)
abfd->is_thin_archive = TRUE;
- return abfd->xvec;
+ return _bfd_no_cleanup;
err:
bfd_release (abfd, tdata);
/* Standard function for alpha libraries. */
-const bfd_target *
+bfd_cleanup
_bfd_vms_lib_alpha_archive_p (bfd *abfd)
{
return _bfd_vms_lib_archive_p (abfd, vms_lib_alpha);
/* Standard function for ia64 libraries. */
-const bfd_target *
+bfd_cleanup
_bfd_vms_lib_ia64_archive_p (bfd *abfd)
{
return _bfd_vms_lib_archive_p (abfd, vms_lib_ia64);
/* Standard function for text libraries. */
-static const bfd_target *
+static bfd_cleanup
_bfd_vms_lib_txt_archive_p (bfd *abfd)
{
return _bfd_vms_lib_archive_p (abfd, vms_lib_txt);
/* Check whether ABFD is a WebAssembly module; if so, scan it. */
-static const bfd_target *
+static bfd_cleanup
wasm_object_p (bfd *abfd)
{
bfd_boolean error;
if (s != NULL && wasm_scan_name_function_section (abfd, s))
abfd->flags |= HAS_SYMS;
- return abfd->xvec;
+ return _bfd_no_cleanup;
}
/* BFD_JUMP_TABLE_WRITE */
return 0;
}
-const bfd_target *
+bfd_cleanup
bfd_sym_object_p (bfd *abfd)
{
bfd_sym_version version = -1;
if (bfd_sym_scan (abfd, version, mdata) != 0)
goto wrong;
- return abfd->xvec;
+ return _bfd_no_cleanup;
wrong:
bfd_set_error (bfd_error_wrong_format);
(bfd *, FILE *);
extern int bfd_sym_scan
(bfd *, bfd_sym_version, bfd_sym_data_struct *);
-extern const bfd_target * bfd_sym_object_p
+extern bfd_cleanup bfd_sym_object_p
(bfd *);
extern void bfd_sym_get_symbol_info
(bfd *, asymbol *, symbol_info *);
+2020-03-02 Alan Modra <amodra@gmail.com>
+
+ * plugin.c (plugin_object_p): Return a bfd_cleanup.
+ (plugin_cleanup): New function.
+
2020-03-01 H.J. Lu <hongjiu.lu@intel.com>
PR ld/25618
struct bfd_link_hash_entry *,
bfd *, asection *, bfd_vma, flagword);
-static const bfd_target * plugin_object_p (bfd *);
+static bfd_cleanup plugin_object_p (bfd *);
#if !defined (HAVE_DLFCN_H) && defined (HAVE_WINDOWS_H)
return copy;
}
-static const bfd_target *
+static void
+plugin_cleanup (bfd *abfd ATTRIBUTE_UNUSED)
+{
+}
+
+static bfd_cleanup
plugin_object_p (bfd *ibfd)
{
int claimed;
if (ibfd->plugin_format != bfd_plugin_unknown)
{
if (ibfd->plugin_format == bfd_plugin_yes)
- return ibfd->plugin_dummy_bfd->xvec;
+ return plugin_cleanup;
else
return NULL;
}
ibfd->plugin_dummy_bfd = abfd;
bfd_make_readable (abfd);
abfd->no_export = ibfd->no_export;
- return abfd->xvec;
+ return plugin_cleanup;
}
else
{