bfd_cleanup for object_p
authorAlan Modra <amodra@gmail.com>
Mon, 2 Mar 2020 04:51:09 +0000 (15:21 +1030)
committerAlan Modra <amodra@gmail.com>
Mon, 2 Mar 2020 09:00:48 +0000 (19:30 +1030)
The object_p (and archive_p, core_file_p) functions are not supposed
to have any target specific malloc'd memory attached to the bfd on
their return.  This should be obvious on a failure return, but it's
also true for a successful return.  The reason is that even though the
object_p recognises the file, that particular target may not be used
and thus the bfd won't be closed calling close_and_cleanup for the
target that allocated the memory.

It turns out that the object_p bfd_target* return value isn't needed.
In all cases except ld/plugin.c the target is abfd->xvec and with
ld/plugin.c the target isn't used.  So this patch returns a cleanup
function from object_p instead, called in bfd_check_format_matches to
tidy the bfd before trying a different target match.  The only cleanup
that does anything at this stage is the alpha-vms one.

bfd/
* 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.
ld/
* plugin.c (plugin_object_p): Return a bfd_cleanup.
(plugin_cleanup): New function.

51 files changed:
bfd/ChangeLog
bfd/aout-target.h
bfd/aout-tic30.c
bfd/aoutx.h
bfd/archive.c
bfd/bfd-in2.h
bfd/binary.c
bfd/coff-alpha.c
bfd/coff-ia64.c
bfd/coff-rs6000.c
bfd/coff-sh.c
bfd/coff-stgo32.c
bfd/coff64-rs6000.c
bfd/coffgen.c
bfd/elf-bfd.h
bfd/elfcode.h
bfd/elfcore.h
bfd/format.c
bfd/i386msdos.c
bfd/ihex.c
bfd/libaout.h
bfd/libbfd-in.h
bfd/libbfd.c
bfd/libbfd.h
bfd/libcoff-in.h
bfd/libcoff.h
bfd/mach-o-aarch64.c
bfd/mach-o-arm.c
bfd/mach-o-i386.c
bfd/mach-o-x86-64.c
bfd/mach-o.c
bfd/mach-o.h
bfd/mmo.c
bfd/pdp11.c
bfd/pef.c
bfd/peicode.h
bfd/plugin.c
bfd/plugin.h
bfd/ppcboot.c
bfd/rs6000-core.c
bfd/som.c
bfd/srec.c
bfd/targets.c
bfd/tekhex.c
bfd/vms-alpha.c
bfd/vms-lib.c
bfd/wasm-module.c
bfd/xsym.c
bfd/xsym.h
ld/ChangeLog
ld/plugin.c

index 116b89397da610abcf8b7e9d7fd1ce2b9548a333..a917631b3884ea5bfccc777373809d65fb519320 100644 (file)
@@ -1,3 +1,72 @@
+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
index 00024e6be284208ccddf51cea0c27bca461943bc..365202e0ce3364d22a1ef647c413d94921af54f8 100644 (file)
@@ -34,7 +34,7 @@ extern reloc_howto_type * NAME (aout, reloc_name_lookup) (bfd *, const char *);
    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);
@@ -121,19 +121,19 @@ MY (callback) (bfd *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)
@@ -164,7 +164,7 @@ MY (object_p) (bfd *abfd)
   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)
@@ -185,7 +185,7 @@ MY (object_p) (bfd *abfd)
     }
 #endif /* ENTRY_CAN_BE_ZERO */
 
-  return target;
+  return cleanup;
 }
 #define MY_object_p MY (object_p)
 #endif
index 06f401cc7e5effbd93406a4c4d0b8651c05b9564..222d1f0e30d74c57bcc081cfc9170d4610d0fd8a 100644 (file)
@@ -331,7 +331,7 @@ tic30_aout_reloc_howto (bfd *abfd,
 /* 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);
@@ -388,7 +388,7 @@ tic30_aout_callback (bfd *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
@@ -547,12 +547,12 @@ tic30_aout_final_link_relocate (reloc_howto_type *howto,
 
 /* 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)
@@ -582,7 +582,7 @@ tic30_aout_object_p (bfd *abfd)
   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)
@@ -603,7 +603,7 @@ tic30_aout_object_p (bfd *abfd)
     }
 #endif
 
-  return target;
+  return cleanup;
 }
 
 /* Copy private section data.  This actually does nothing with the
index 4fb1282fb6e7c294475a502002993d45c7adc1e4..41ced3dc72aadd100996cd43aa4ff385172094ef 100644 (file)
@@ -452,13 +452,13 @@ DESCRIPTION
        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);
@@ -591,7 +591,7 @@ NAME (aout, some_aout_object_p) (bfd *abfd,
   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
index 71bc6a4323c999be30d551d42b05f013043276b8..0c009f10de876b8374141d84b6540252b1f93e3c 100644 (file)
@@ -842,7 +842,7 @@ _bfd_noarchive_openr_next_archived_file (bfd *archive,
   return (bfd *) _bfd_ptr_bfd_null_error (archive);
 }
 
-const bfd_target *
+bfd_cleanup
 bfd_generic_archive_p (bfd *abfd)
 {
   struct artdata *tdata_hold;
@@ -924,7 +924,7 @@ bfd_generic_archive_p (bfd *abfd)
        }
     }
 
-  return abfd->xvec;
+  return _bfd_no_cleanup;
 }
 
 /* Some constants for a 32 bit BSD archive structure.  We do not
index 44bc7041cdc9ec7eaf85b212b651a44ee9133914..37114607b51521d51aecf36101e1b8e12efd027e 100644 (file)
@@ -7295,6 +7295,8 @@ typedef struct bfd_link_info _bfd_link_info;
 /* 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.  */
@@ -7359,9 +7361,9 @@ typedef struct bfd_target
   /* 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 *);
index 0683e414d6eb1c8008a7171f59d2396a87a03439..999de0d8c41a4e7d8e5072de86983c1717ab900d 100644 (file)
@@ -53,7 +53,7 @@ binary_mkobject (bfd *abfd ATTRIBUTE_UNUSED)
    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;
@@ -86,7 +86,7 @@ binary_object_p (bfd *abfd)
 
   abfd->tdata.any = (void *) sec;
 
-  return abfd->xvec;
+  return _bfd_no_cleanup;
 }
 
 #define binary_close_and_cleanup     _bfd_generic_close_and_cleanup
index 821e5591a9a9562746abf654dafb40dfada6e477..b86a8a259b584dd30481389b398fa4f6851ca932 100644 (file)
@@ -398,10 +398,10 @@ static reloc_howto_type alpha_howto_table[] =
 \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);
 
index 180cf9db8a8604f52641d892dddbd01403390a66..07e54037f9cd0777edbb4933cec2c0fbd404c8fc 100644 (file)
@@ -67,7 +67,7 @@ in_reloc_p (bfd * abfd ATTRIBUTE_UNUSED,
 
 #include "coffcode.h"
 
-static const bfd_target *
+static bfd_cleanup
 ia64coff_object_p (bfd *abfd)
 {
 #ifdef COFF_IMAGE_WITH_PE
index 1cc708ce1b34071a0dbbff02331cad2c43f4929d..2dd68e08c3b8a3c0832798f9e56ab827740fd1a0 100644 (file)
@@ -38,7 +38,7 @@ extern bfd_boolean _bfd_xcoff_is_local_label_name (bfd *, const char *);
 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 *);
@@ -77,7 +77,7 @@ void xcoff_rtype2howto (arelent *, struct internal_reloc *);
 #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);
@@ -1380,7 +1380,7 @@ _bfd_xcoff_slurp_armap (bfd *abfd)
 
 /* See if this is an XCOFF archive.  */
 
-const bfd_target *
+bfd_cleanup
 _bfd_xcoff_archive_p (bfd *abfd)
 {
   struct artdata *tdata_hold;
@@ -1481,7 +1481,7 @@ _bfd_xcoff_archive_p (bfd *abfd)
       return NULL;
     }
 
-  return abfd->xvec;
+  return _bfd_no_cleanup;
 }
 
 /* Read the archive header in an XCOFF archive.  */
index 986cd4d1d04f33d0f61847e22689670f4a3dce3a..b46a5e34f39f7f9d7d1de5011b188d270dc2a482 100644 (file)
@@ -3044,7 +3044,7 @@ CREATE_LITTLE_COFF_TARGET_VEC (TARGET_SYM, TARGET_SHL_NAME, BFD_IS_RELAXABLE,
 /* 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)
index 6984b4219ee8197f86e451626d036703bb49a56a..676022872aea4f58899da7ab73ad2294d74b2fe8 100644 (file)
@@ -93,7 +93,7 @@ create_go32_stub (bfd *);
 #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
 
@@ -406,7 +406,7 @@ go32_stubbed_coff_bfd_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
 /* 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];
index bb546239fc3c32d54265ec55e971367d38f4013d..cca876eb4e083335bbc78d5ab68f98785200f1db 100644 (file)
@@ -155,7 +155,7 @@ static bfd_boolean xcoff64_ppc_relocate_section
    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 *);
@@ -238,7 +238,7 @@ bfd_boolean (*xcoff64_calculate_relocation[XCOFF_MAX_CALCULATE_RELOCATION])
 #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);
@@ -1991,7 +1991,7 @@ xcoff64_slurp_armap (bfd *abfd)
 
 /* See if this is an NEW XCOFF archive.  */
 
-static const bfd_target *
+static bfd_cleanup
 xcoff64_archive_p (bfd *abfd)
 {
   struct artdata *tdata_hold;
@@ -2058,7 +2058,7 @@ xcoff64_archive_p (bfd *abfd)
       return NULL;
     }
 
-  return abfd->xvec;
+  return _bfd_no_cleanup;
 }
 
 
@@ -2805,7 +2805,7 @@ const bfd_target rs6000_xcoff64_vec =
     &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 *);
index daaaba95c588d10ac29181223d140a5348f7058f..6d84d512844411ac1ee7d46e00885aa92ee2bd9b 100644 (file)
@@ -225,12 +225,12 @@ make_a_section_from_file (bfd *abfd,
 
 /* 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,
@@ -300,7 +300,7 @@ coff_real_object_p (bfd *abfd,
     }
 
   _bfd_coff_free_symbols (abfd);
-  return abfd->xvec;
+  return _bfd_no_cleanup;
 
  fail:
   _bfd_coff_free_symbols (abfd);
@@ -309,13 +309,13 @@ coff_real_object_p (bfd *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;
index 61e733f068deecc046a4656c581dfd5dd6f5ad12..38a9aa060192818dc9f09da0c95051840361ae9f 100644 (file)
@@ -2400,9 +2400,9 @@ extern bfd_boolean _bfd_elf_init_file_header (bfd *, struct bfd_link_info *);
 
 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 *);
@@ -2448,9 +2448,9 @@ extern void bfd_elf32_write_relocs
 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 *);
index b67ea8c7d2e88dd644d2da4b0ed53f4203ddfb32..600abfe836e4bafed2a4d66777835da7257277ba 100644 (file)
@@ -497,7 +497,7 @@ elf_file_p (Elf_External_Ehdr *x_ehdrp)
    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 */
@@ -853,7 +853,7 @@ elf_object_p (bfd *abfd)
            s->flags |= SEC_DEBUGGING;
        }
     }
-  return target;
+  return _bfd_no_cleanup;
 
  got_wrong_format_error:
   bfd_set_error (bfd_error_wrong_format);
index 591ca531a6325d44f59059232adb0df1db393b71..44707ebb60fbd7659693fcffd06ef0064c4cc42f 100644 (file)
@@ -83,7 +83,7 @@ elf_core_file_matches_executable_p (bfd *core_bfd, bfd *exec_bfd)
     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.  */
@@ -314,7 +314,7 @@ elf_core_file_p (bfd *abfd)
 
   /* 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);
index 659d407018b81e791dd1231ec38c39afbbd1c278..b181742f3b1699660b4e493f60f81bc6dc7ca757 100644 (file)
@@ -140,13 +140,15 @@ bfd_preserve_save (bfd *abfd, struct bfd_preserve *preserve)
 /* 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.  */
@@ -220,6 +222,7 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
   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;
@@ -258,9 +261,9 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
       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
@@ -291,7 +294,6 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
 
   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
@@ -309,7 +311,7 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
       /* 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)
@@ -325,10 +327,10 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
       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
@@ -345,11 +347,11 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
              /* 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)
@@ -360,7 +362,7 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
              if (match_priority <= best_match)
                {
                  /* This format checks out as ok!  */
-                 right_targ = temp;
+                 right_targ = abfd->xvec;
                  best_count++;
                }
            }
@@ -378,7 +380,7 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
 
          if (preserve_match.marker == NULL)
            {
-             match_targ = temp;
+             match_targ = abfd->xvec;
              if (!bfd_preserve_save (abfd, &preserve_match))
                goto err_ret;
            }
@@ -467,12 +469,12 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
         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:
index 11c5da6bed4068bb6beb09ca5c2a9851c16def68..5b56751cd30bd59f36337ab13548d8085cc894ad 100644 (file)
@@ -41,7 +41,7 @@ msdos_mkobject (bfd *abfd)
   return aout_32_mkobject (abfd);
 }
 
-static const bfd_target *
+static bfd_cleanup
 msdos_object_p (bfd *abfd)
 {
   struct external_DOS_hdr hdr;
@@ -112,7 +112,7 @@ msdos_object_p (bfd *abfd)
   bfd_set_section_size (section, size);
   section->alignment_power = 4;
 
-  return abfd->xvec;
+  return _bfd_no_cleanup;
 }
 
 static int
index 958a84b50705899d7816161146238bd7064a41e5..68671cc6239357ec76088eccf87cb11f6e5227ff 100644 (file)
@@ -487,7 +487,7 @@ ihex_scan (bfd *abfd)
 
 /* Try to recognize an Intel Hex file.  */
 
-static const bfd_target *
+static bfd_cleanup
 ihex_object_p (bfd *abfd)
 {
   void * tdata_save;
@@ -538,7 +538,7 @@ ihex_object_p (bfd *abfd)
       return NULL;
     }
 
-  return abfd->xvec;
+  return _bfd_no_cleanup;
 }
 
 /* Read the contents of a section in an Intel Hex file.  */
index 81ef4cffd5ebb8dfc6658636038f1bfce7a5c222..bdf917e5561536e1e811b01cd88a42f170dbf33f 100644 (file)
@@ -475,8 +475,8 @@ extern bfd_boolean NAME (aout, squirt_out_relocs)
 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 *);
index 6d796b7ef8952f28aa3932a959adda54b93cb0a4..c8cf079a919f14157d88c90059212619cc69385f 100644 (file)
@@ -141,7 +141,7 @@ extern bfd_boolean _bfd_generic_mkarchive
   (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;
@@ -227,8 +227,9 @@ extern void _bfd_void_bfd_asection
 
 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;
@@ -425,9 +426,9 @@ extern symindex _bfd_vms_lib_find_symbol
   (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;
index cb7c3b5aba0872bf7666da5db5b054b1bdc76fc5..3579ddb855a643da28c0edf59b43399da324f894 100644 (file)
@@ -245,7 +245,7 @@ _bfd_nocore_core_file_pid (bfd *ignore_abfd ATTRIBUTE_UNUSED)
   return 0;
 }
 
-const bfd_target *
+bfd_cleanup
 _bfd_dummy_target (bfd *ignore_abfd ATTRIBUTE_UNUSED)
 {
   bfd_set_error (bfd_error_wrong_format);
index 2391500c330cfb17723b6a73ba3caa38a50c51a2..3c184fcadadf82cb093753f2d10ddeb6b0af9dd7 100644 (file)
@@ -146,7 +146,7 @@ extern bfd_boolean _bfd_generic_mkarchive
   (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;
@@ -232,8 +232,9 @@ extern void _bfd_void_bfd_asection
 
 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;
@@ -430,9 +431,9 @@ extern symindex _bfd_vms_lib_find_symbol
   (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;
index 807817c94eeaca01c5d541d79d97c6280e02f8ae..3030a65fa77128920d94fab9b301a3d7ca6559de 100644 (file)
@@ -299,7 +299,7 @@ struct coff_reloc_cookie
 #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);
index e6af9d6130d577a7a8ce37d68c0bc4800c9b26ee..4c7be6e935a8755c0ba810f6d2c7a0b976d18bf3 100644 (file)
@@ -303,7 +303,7 @@ struct coff_reloc_cookie
 #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);
index f3406b3be25eade0ccde817ab741b6c95c93b3e2..c71b92e47cad0bbcabc06fe8c7a92c2940bc6dea 100644 (file)
 #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,
index efdb6bfb988d31e08393c5b0c5ccf00782eeb97a..f4afce71c86a40594261799e967f0173ed22420b 100644 (file)
 #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,
index 2fcd0deee1b844cb178d483772702b1873235b89..6ef27d1cd131794b311601eca25689300f6f7c71 100644 (file)
 #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,
index fdc6558f5422616ba8b166a8dee028535d609a1d..9a6b58bc271f6139ab12c95acc9e4a36aafd79bc 100644 (file)
 #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,
index 4b7be6eb4e19c9a2d96a5f4bd5757b57ba909803..ee58a7adfae1375468c9dee6beb0ef450ab0922f 100644 (file)
@@ -5365,7 +5365,7 @@ bfd_mach_o_gen_mkobject (bfd *abfd)
   return TRUE;
 }
 
-const bfd_target *
+bfd_cleanup
 bfd_mach_o_header_p (bfd *abfd,
                     file_ptr hdr_off,
                     bfd_mach_o_filetype file_type,
@@ -5436,7 +5436,7 @@ bfd_mach_o_header_p (bfd *abfd,
   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);
@@ -5445,13 +5445,13 @@ bfd_mach_o_header_p (bfd *abfd,
   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);
@@ -5501,7 +5501,7 @@ typedef struct mach_o_fat_data_struct
   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;
@@ -5551,7 +5551,7 @@ bfd_mach_o_fat_archive_p (bfd *abfd)
 
   abfd->tdata.mach_o_fat_data = adata;
 
-  return abfd->xvec;
+  return _bfd_no_cleanup;
 
  error:
   if (adata != NULL)
index 468de8e96ea604cda19457e10d02bae22238b5f1..278bdd531545a8668ff63e95945c42a56308dbb4 100644 (file)
@@ -679,9 +679,9 @@ bfd_mach_o_xlat_name;
 
 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);
@@ -713,8 +713,8 @@ char *bfd_mach_o_core_file_failing_command (bfd *);
 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);
index 073c37c0acdcb6916e53ea46ed0425f72a1f0fdf..3b7e5c0c33fcb72a33bd111046a655c94ff16ec0 100644 (file)
--- a/bfd/mmo.c
+++ b/bfd/mmo.c
@@ -386,7 +386,7 @@ static INLINE bfd_byte *mmo_get_loc (asection *, bfd_vma, int);
 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,
@@ -500,7 +500,7 @@ mmo_init (void)
 
 /* Check whether an existing file is an mmo file.  */
 
-static const bfd_target *
+static bfd_cleanup
 mmo_object_p (bfd *abfd)
 {
   struct stat statbuf;
@@ -556,7 +556,7 @@ mmo_object_p (bfd *abfd)
   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);
index 35d45e64806ffae87b7b7121e1090bec5fe4e2d7..c13e742c0da2a2d55a5979f820d7695a901eb81a 100644 (file)
@@ -452,13 +452,13 @@ NAME (aout, make_sections) (bfd *abfd)
    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);
@@ -580,7 +580,7 @@ NAME (aout, some_aout_object_p) (bfd *abfd,
   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
@@ -592,7 +592,7 @@ NAME (aout, some_aout_object_p) (bfd *abfd,
      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
@@ -633,12 +633,12 @@ NAME (aout, some_aout_object_p) (bfd *abfd,
     }
 #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.  */
index b0f6c2d2a7cb81747127a222070adb4928b0b7ba..4e749e1949789946e540420920be43a940d5118d 100644 (file)
--- a/bfd/pef.c
+++ b/bfd/pef.c
@@ -589,7 +589,7 @@ bfd_pef_read_header (bfd *abfd, bfd_pef_header *header)
   return 0;
 }
 
-static const bfd_target *
+static bfd_cleanup
 bfd_pef_object_p (bfd *abfd)
 {
   bfd_pef_header header;
@@ -608,7 +608,7 @@ bfd_pef_object_p (bfd *abfd)
   if (bfd_pef_scan (abfd, &header, mdata))
     goto wrong;
 
-  return abfd->xvec;
+  return _bfd_no_cleanup;
 
  wrong:
   bfd_set_error (bfd_error_wrong_format);
@@ -1126,7 +1126,7 @@ bfd_pef_xlib_scan (bfd *abfd, bfd_pef_xlib_header *header)
   return 0;
 }
 
-static const bfd_target *
+static bfd_cleanup
 bfd_pef_xlib_object_p (bfd *abfd)
 {
   bfd_pef_xlib_header header;
@@ -1151,7 +1151,7 @@ bfd_pef_xlib_object_p (bfd *abfd)
       return NULL;
     }
 
-  return abfd->xvec;
+  return _bfd_no_cleanup;
 }
 
 const bfd_target pef_xlib_vec =
index f569ccf389321c969ea1a01bc9a417c39c97c8b4..c5a92afefc4604b29c92a2ac0f56dbc4a4546df9 100644 (file)
@@ -122,7 +122,7 @@ typedef struct
 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
@@ -1142,7 +1142,7 @@ pe_ILF_build_a_bfd (bfd *     abfd,
 /* 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];
@@ -1300,7 +1300,7 @@ pe_ILF_object_p (bfd * abfd)
       return NULL;
     }
 
-  return abfd->xvec;
+  return _bfd_no_cleanup;
 }
 
 static void
@@ -1394,7 +1394,7 @@ pe_bfd_read_buildid (bfd *abfd)
   free (data);
 }
 
-static const bfd_target *
+static bfd_cleanup
 pe_bfd_object_p (bfd * abfd)
 {
   bfd_byte buffer[6];
@@ -1404,7 +1404,7 @@ pe_bfd_object_p (bfd * abfd)
   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.  */
index 72e55a0f60731302216455ddfc30d135ee53cb88..a0f172d363793753601db6afa892c97f79da0aab 100644 (file)
@@ -733,7 +733,7 @@ try_load_plugin (const char *pname,
 /* 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;
 
@@ -774,7 +774,7 @@ bfd_plugin_target_p (const bfd_target *target)
 /* 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;
 }
@@ -862,7 +862,7 @@ load_plugin (bfd *abfd)
 }
 
 
-static const bfd_target *
+static bfd_cleanup
 bfd_plugin_object_p (bfd *abfd)
 {
   if (ld_plugin_object_p)
@@ -871,7 +871,7 @@ bfd_plugin_object_p (bfd *abfd)
   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
index b2d5e50137f2c30b436c3c14d3017d38676b6b5b..af5d1f4cfa9d395878b6331c4f94dcc205756d9f 100644 (file)
@@ -27,7 +27,7 @@ void bfd_plugin_set_plugin (const char *);
 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
 {
index 24f3e0655e523f3490fa7a16c9f72ebc3d64e250..9d9d187613a1cd85ef406dce89ffe63c24343931 100644 (file)
@@ -130,7 +130,7 @@ ppcboot_set_arch_mach (bfd *abfd,
    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;
@@ -207,7 +207,7 @@ ppcboot_object_p (bfd *abfd)
   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
index ba7f896b998fd398339a781cd353c4fc570a0c32..8e2dd06b464c9b199971bf75ee7d71b6a4042d1c 100644 (file)
@@ -277,7 +277,7 @@ typedef union
 /* 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);
@@ -332,7 +332,7 @@ make_bfd_asection (bfd *abfd, const char *name, flagword flags,
 /* 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;
@@ -686,7 +686,7 @@ rs6000coff_core_p (bfd *abfd)
   }
 #endif
 
-  return abfd->xvec;           /* This is garbage for now.  */
+  return _bfd_no_cleanup;
 
  fail:
   bfd_release (abfd, abfd->tdata.any);
index 9f37b10f96c4efd4c4931bdeb7ee9ce3e67c0dbd..3aa3d60b02bcd61372a61695f77fe01b27d85969 100644 (file)
--- a/bfd/som.c
+++ b/bfd/som.c
@@ -1945,7 +1945,7 @@ som_swap_lst_header_in (struct som_external_lst_header *src,
 /* 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,
@@ -2060,7 +2060,7 @@ som_object_setup (bfd *abfd,
                                  + 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
@@ -2386,7 +2386,7 @@ setup_sections (bfd *abfd,
 
 /* 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;
index 266c2b19ebbcd82f25fa09bd6d8c08b40d3ea5f4..5ca4f36ae5944ae34cb7c9d7146f03e626efc453 100644 (file)
@@ -646,7 +646,7 @@ srec_scan (bfd *abfd)
 
 /* 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;
@@ -676,12 +676,12 @@ srec_object_p (bfd *abfd)
   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;
@@ -711,7 +711,7 @@ symbolsrec_object_p (bfd *abfd)
   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.  */
index e7cd9a810cb0d1506f8413f565540cd2f8b29d07..39683e83d414f6689710491901e382d68bd47520 100644 (file)
@@ -176,6 +176,8 @@ DESCRIPTION
 .{* 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.  *}
@@ -240,9 +242,9 @@ DESCRIPTION
 .  {* 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 *);
index aaaffa05c27819a6ad257fcafae94f8074e48e39..c2834b32d0cdbcd4062e20e1ff32711b4ab63726 100644 (file)
@@ -600,7 +600,7 @@ tekhex_mkobject (bfd *abfd)
 /* 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];
@@ -619,7 +619,7 @@ tekhex_object_p (bfd *abfd)
   if (!pass_over (abfd, first_phase))
     return NULL;
 
-  return abfd->xvec;
+  return _bfd_no_cleanup;
 }
 
 static void
index 272d80ab4c84af8919adf65344015c6dc326b624..241dab340d7c723f902c3337e79c6f68ca3b39bc 100644 (file)
@@ -2707,7 +2707,7 @@ alpha_vms_free_private (bfd *abfd)
 /* 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;
@@ -2826,7 +2826,7 @@ alpha_vms_object_p (bfd *abfd)
   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);
index 66a40bc91ca8bfbb078cb4ffeca57b1f5072e2ab..a6335218fa491671c167c2854ff3ac0c06b968d4 100644 (file)
@@ -489,7 +489,7 @@ vms_lib_read_index (bfd *abfd, int idx, unsigned int *nbrel)
 
 /* 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;
@@ -693,7 +693,7 @@ _bfd_vms_lib_archive_p (bfd *abfd, enum vms_lib_kind kind)
   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);
@@ -703,7 +703,7 @@ _bfd_vms_lib_archive_p (bfd *abfd, enum vms_lib_kind kind)
 
 /* 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);
@@ -711,7 +711,7 @@ _bfd_vms_lib_alpha_archive_p (bfd *abfd)
 
 /* 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);
@@ -719,7 +719,7 @@ _bfd_vms_lib_ia64_archive_p (bfd *abfd)
 
 /* 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);
index fa8648b9acd7d2f7fcf767484b402a82dc1bbd89..ac78692816e9c9a1c05f3d14ea511437e0b78a79 100644 (file)
@@ -731,7 +731,7 @@ wasm_get_symbol_info (bfd *abfd ATTRIBUTE_UNUSED,
 
 /* 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;
@@ -761,7 +761,7 @@ wasm_object_p (bfd *abfd)
   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 */
index 3071a9de3f7e2e876f6450b856f683235fe027a6..525d6d98abc1bc385acce6593fb57aca8ae7bde9 100644 (file)
@@ -2230,7 +2230,7 @@ bfd_sym_scan (bfd *abfd, bfd_sym_version version, bfd_sym_data_struct *mdata)
   return 0;
 }
 
-const bfd_target *
+bfd_cleanup
 bfd_sym_object_p (bfd *abfd)
 {
   bfd_sym_version version = -1;
@@ -2247,7 +2247,7 @@ bfd_sym_object_p (bfd *abfd)
   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);
index 061efd6b058ddf63de85f88c337affa8d5f970c7..393b72b5e0a1de30229a35a001cb2e0db251519e 100644 (file)
@@ -686,7 +686,7 @@ extern void bfd_sym_display_type_information_table
   (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 *);
index 927074e4ba70719a7212bb710853703a46d7d19d..14a917b25bf9e0700fbe65e9a996196c5ef2ad14 100644 (file)
@@ -1,3 +1,8 @@
+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
index af3f9e2ffe88e7d86fca4cba9c7eb78f3bc5f9d4..4ef4a236650ce97b51ed6bd7edd5369a035f18f6 100644 (file)
@@ -175,7 +175,7 @@ static bfd_boolean plugin_notice (struct bfd_link_info *,
                                  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)
 
@@ -1164,7 +1164,12 @@ plugin_strdup (bfd *abfd, const char *str)
   return copy;
 }
 
-static const bfd_target *
+static void
+plugin_cleanup (bfd *abfd ATTRIBUTE_UNUSED)
+{
+}
+
+static bfd_cleanup
 plugin_object_p (bfd *ibfd)
 {
   int claimed;
@@ -1179,7 +1184,7 @@ plugin_object_p (bfd *ibfd)
   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;
     }
@@ -1240,7 +1245,7 @@ plugin_object_p (bfd *ibfd)
       ibfd->plugin_dummy_bfd = abfd;
       bfd_make_readable (abfd);
       abfd->no_export = ibfd->no_export;
-      return abfd->xvec;
+      return plugin_cleanup;
     }
   else
     {
This page took 0.056205 seconds and 4 git commands to generate.