Make bfd_byte an int8_t, flagword a uint32_t
[binutils-gdb.git] / bfd / targets.c
index 7dbc3a5dbf6d4204e97ae1c7905354bb1365bebe..44fb5a32c746ede157b29c6fa5e5ead8b9258e1b 100644 (file)
@@ -1,5 +1,5 @@
 /* Generic target-file-type support for the BFD library.
-   Copyright (C) 1990-2022 Free Software Foundation, Inc.
+   Copyright (C) 1990-2023 Free Software Foundation, Inc.
    Written by Cygnus Support.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -162,10 +162,7 @@ DESCRIPTION
 .  bfd_target_verilog_flavour,
 .  bfd_target_ihex_flavour,
 .  bfd_target_som_flavour,
-.  bfd_target_os9k_flavour,
-.  bfd_target_versados_flavour,
 .  bfd_target_msdos_flavour,
-.  bfd_target_ovax_flavour,
 .  bfd_target_evax_flavour,
 .  bfd_target_mmo_flavour,
 .  bfd_target_mach_o_flavour,
@@ -686,7 +683,8 @@ extern const bfd_target aarch64_elf64_be_cloudabi_vec;
 extern const bfd_target aarch64_elf64_le_vec;
 extern const bfd_target aarch64_elf64_le_cloudabi_vec;
 extern const bfd_target aarch64_mach_o_vec;
-extern const bfd_target aarch64_pei_vec;
+extern const bfd_target aarch64_pei_le_vec;
+extern const bfd_target aarch64_pe_le_vec;
 extern const bfd_target alpha_ecoff_le_vec;
 extern const bfd_target alpha_elf64_vec;
 extern const bfd_target alpha_elf64_fbsd_vec;
@@ -959,7 +957,6 @@ extern const bfd_target binary_vec;
 extern const bfd_target ihex_vec;
 
 /* All of the xvecs for core files.  */
-extern const bfd_target core_aix386_vec;
 extern const bfd_target core_cisco_be_vec;
 extern const bfd_target core_cisco_le_vec;
 extern const bfd_target core_hppabsd_vec;
@@ -968,7 +965,6 @@ extern const bfd_target core_irix_vec;
 extern const bfd_target core_netbsd_vec;
 extern const bfd_target core_osf_vec;
 extern const bfd_target core_ptrace_vec;
-extern const bfd_target core_sco5_vec;
 extern const bfd_target core_trad_vec;
 
 static const bfd_target * const _bfd_target_vector[] =
@@ -999,7 +995,8 @@ static const bfd_target * const _bfd_target_vector[] =
        &aarch64_elf64_le_vec,
        &aarch64_elf64_le_cloudabi_vec,
        &aarch64_mach_o_vec,
-       &aarch64_pei_vec,
+       &aarch64_pe_le_vec,
+       &aarch64_pei_le_vec,
 #endif
 
 #ifdef BFD64
@@ -1392,9 +1389,6 @@ static const bfd_target * const _bfd_target_vector[] =
 
 /* Add any required traditional-core-file-handler.  */
 
-#ifdef AIX386_CORE
-       &core_aix386_vec,
-#endif
 #if 0
        /* We don't include cisco_core_*_vec.  Although it has a magic number,
           the magic number isn't at the beginning of the file, and thus
@@ -1420,9 +1414,6 @@ static const bfd_target * const _bfd_target_vector[] =
 #ifdef PTRACE_CORE
        &core_ptrace_vec,
 #endif
-#ifdef SCO5_CORE
-       &core_sco5_vec,
-#endif
 #ifdef TRAD_CORE
        &core_trad_vec,
 #endif
@@ -1458,7 +1449,8 @@ const bfd_target *const *const bfd_associated_vector = _bfd_associated_vector;
 const size_t _bfd_target_vector_entries = ARRAY_SIZE (_bfd_target_vector);
 
 /* A place to stash a warning from _bfd_check_format.  */
-static const char *per_xvec_warn[ARRAY_SIZE (_bfd_target_vector) + 1];
+static struct per_xvec_message *per_xvec_warn[ARRAY_SIZE (_bfd_target_vector)
+                                             + 1];
 \f
 /* This array maps configuration triplets onto BFD vectors.  */
 
@@ -1479,26 +1471,58 @@ static const struct targmatch bfd_target_match[] = {
 };
 
 /*
+CODE_FRAGMENT
+.{* Cached _bfd_check_format messages are put in this.  *}
+.struct per_xvec_message
+.{
+.  struct per_xvec_message *next;
+.  char message[];
+.};
+.
 INTERNAL_FUNCTION
        _bfd_per_xvec_warn
 
 SYNOPSIS
-       const char **_bfd_per_xvec_warn (const bfd_target *);
+       struct per_xvec_message **_bfd_per_xvec_warn (const bfd_target *, size_t);
 
 DESCRIPTION
        Return a location for the given target xvec to use for
-       warnings specific to that target.
+       warnings specific to that target.  If TARG is NULL, returns
+       the array of per_xvec_message pointers, otherwise if ALLOC is
+       zero, returns a pointer to a pointer to the list of messages
+       for TARG, otherwise (both TARG and ALLOC non-zero), allocates
+       a new   per_xvec_message with space for a string of ALLOC
+       bytes and returns a pointer to a pointer to it.  May return a
+       pointer to a NULL pointer on allocation failure.
 */
 
-const char **
-_bfd_per_xvec_warn (const bfd_target *targ)
+struct per_xvec_message **
+_bfd_per_xvec_warn (const bfd_target *targ, size_t alloc)
 {
   size_t idx;
 
+  if (!targ)
+    return per_xvec_warn;
   for (idx = 0; idx < ARRAY_SIZE (_bfd_target_vector); idx++)
     if (_bfd_target_vector[idx] == targ)
       break;
-  return per_xvec_warn + idx;
+  struct per_xvec_message **m = per_xvec_warn + idx;
+  if (!alloc)
+    return m;
+  int count = 0;
+  while (*m)
+    {
+      m = &(*m)->next;
+      count++;
+    }
+  /* Anti-fuzzer measure.  Don't cache more than 5 messages.  */
+  if (count < 5)
+    {
+      *m = bfd_malloc (sizeof (**m) + alloc);
+      if (*m != NULL)
+       (*m)->next = NULL;
+    }
+  return m;
 }
 
 /* Find a target vector, given a name or configuration triplet.  */
@@ -1828,10 +1852,7 @@ bfd_flavour_name (enum bfd_flavour flavour)
     case bfd_target_verilog_flavour: return "Verilog";
     case bfd_target_ihex_flavour: return "Ihex";
     case bfd_target_som_flavour: return "SOM";
-    case bfd_target_os9k_flavour: return "OS9K";
-    case bfd_target_versados_flavour: return "Versados";
     case bfd_target_msdos_flavour: return "MSDOS";
-    case bfd_target_ovax_flavour: return "Ovax";
     case bfd_target_evax_flavour: return "Evax";
     case bfd_target_mmo_flavour: return "mmo";
     case bfd_target_mach_o_flavour: return "MACH_O";