Make bfd_byte an int8_t, flagword a uint32_t
[binutils-gdb.git] / bfd / targets.c
index 8f5abb174e2dfecad62008b68f381d89b423576d..44fb5a32c746ede157b29c6fa5e5ead8b9258e1b 100644 (file)
@@ -1,5 +1,5 @@
 /* Generic target-file-type support for the BFD library.
-   Copyright (C) 1990-2021 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.
@@ -20,6 +20,7 @@
    MA 02110-1301, USA.  */
 
 #include "sysdep.h"
+#include "libiberty.h"
 #include "bfd.h"
 #include "libbfd.h"
 #include "fnmatch.h"
@@ -161,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,
@@ -226,9 +224,9 @@ DESCRIPTION
 .  {* Entries for byte swapping for data. These are different from the
 .     other entry points, since they don't take a BFD as the first argument.
 .     Certain other handlers could do the same.  *}
-.  bfd_uint64_t          (*bfd_getx64) (const void *);
-.  bfd_int64_t   (*bfd_getx_signed_64) (const void *);
-.  void                  (*bfd_putx64) (bfd_uint64_t, void *);
+.  uint64_t      (*bfd_getx64) (const void *);
+.  int64_t       (*bfd_getx_signed_64) (const void *);
+.  void                  (*bfd_putx64) (uint64_t, void *);
 .  bfd_vma       (*bfd_getx32) (const void *);
 .  bfd_signed_vma (*bfd_getx_signed_32) (const void *);
 .  void                  (*bfd_putx32) (bfd_vma, void *);
@@ -237,9 +235,9 @@ DESCRIPTION
 .  void                  (*bfd_putx16) (bfd_vma, void *);
 .
 .  {* Byte swapping for the headers.  *}
-.  bfd_uint64_t          (*bfd_h_getx64) (const void *);
-.  bfd_int64_t   (*bfd_h_getx_signed_64) (const void *);
-.  void                  (*bfd_h_putx64) (bfd_uint64_t, void *);
+.  uint64_t      (*bfd_h_getx64) (const void *);
+.  int64_t       (*bfd_h_getx_signed_64) (const void *);
+.  void                  (*bfd_h_putx64) (uint64_t, void *);
 .  bfd_vma       (*bfd_h_getx32) (const void *);
 .  bfd_signed_vma (*bfd_h_getx_signed_32) (const void *);
 .  void                  (*bfd_h_putx32) (bfd_vma, void *);
@@ -377,6 +375,7 @@ BFD_JUMP_TABLE macros.
 .  NAME##_bfd_is_target_special_symbol, \
 .  NAME##_get_lineno, \
 .  NAME##_find_nearest_line, \
+.  NAME##_find_nearest_line_with_alt, \
 .  NAME##_find_line, \
 .  NAME##_find_inliner_info, \
 .  NAME##_bfd_make_debug_symbol, \
@@ -407,6 +406,11 @@ BFD_JUMP_TABLE macros.
 .                                 struct bfd_section *, bfd_vma,
 .                                 const char **, const char **,
 .                                 unsigned int *, unsigned int *);
+.  bool (*_bfd_find_nearest_line_with_alt) (bfd *, const char *,
+.                                          struct bfd_symbol **,
+.                                          struct bfd_section *, bfd_vma,
+.                                          const char **, const char **,
+.                                          unsigned int *, unsigned int *);
 .  bool (*_bfd_find_line) (bfd *, struct bfd_symbol **,
 .                         struct bfd_symbol *, const char **,
 .                         unsigned int *);
@@ -679,12 +683,15 @@ 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_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;
 extern const bfd_target alpha_vms_vec;
 extern const bfd_target alpha_vms_lib_txt_vec;
 extern const bfd_target am33_elf32_linux_vec;
+extern const bfd_target amdgcn_elf64_le_vec;
 extern const bfd_target aout_vec;
 extern const bfd_target arc_elf32_be_vec;
 extern const bfd_target arc_elf32_le_vec;
@@ -762,14 +769,11 @@ extern const bfd_target ia64_elf64_vms_vec;
 extern const bfd_target ia64_pei_vec;
 extern const bfd_target ip2k_elf32_vec;
 extern const bfd_target iq2000_elf32_vec;
-extern const bfd_target k1om_elf64_vec;
-extern const bfd_target k1om_elf64_fbsd_vec;
-extern const bfd_target l1om_elf64_vec;
-extern const bfd_target l1om_elf64_fbsd_vec;
 extern const bfd_target lm32_elf32_vec;
 extern const bfd_target lm32_elf32_fdpic_vec;
 extern const bfd_target loongarch_elf64_vec;
 extern const bfd_target loongarch_elf32_vec;
+extern const bfd_target loongarch64_pei_vec;
 extern const bfd_target m32c_elf32_vec;
 extern const bfd_target m32r_elf32_vec;
 extern const bfd_target m32r_elf32_le_vec;
@@ -835,6 +839,7 @@ extern const bfd_target nios2_elf32_le_vec;
 extern const bfd_target ns32k_aout_pc532mach_vec;
 extern const bfd_target ns32k_aout_pc532nbsd_vec;
 extern const bfd_target or1k_elf32_vec;
+extern const bfd_target pdb_vec;
 extern const bfd_target pdp11_aout_vec;
 extern const bfd_target pef_vec;
 extern const bfd_target pef_xlib_vec;
@@ -935,7 +940,6 @@ extern const bfd_target x86_64_mach_o_vec;
 extern const bfd_target x86_64_pe_vec;
 extern const bfd_target x86_64_pe_big_vec;
 extern const bfd_target x86_64_pei_vec;
-extern const bfd_target xc16x_elf32_vec;
 extern const bfd_target xgate_elf32_vec;
 extern const bfd_target xstormy16_elf32_vec;
 extern const bfd_target xtensa_elf32_be_vec;
@@ -953,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;
@@ -962,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[] =
@@ -993,6 +995,12 @@ static const bfd_target * const _bfd_target_vector[] =
        &aarch64_elf64_le_vec,
        &aarch64_elf64_le_cloudabi_vec,
        &aarch64_mach_o_vec,
+       &aarch64_pe_le_vec,
+       &aarch64_pei_le_vec,
+#endif
+
+#ifdef BFD64
+       &amdgcn_elf64_le_vec,
 #endif
 
 #ifdef BFD64
@@ -1120,13 +1128,6 @@ static const bfd_target * const _bfd_target_vector[] =
        &ip2k_elf32_vec,
        &iq2000_elf32_vec,
 
-#ifdef BFD64
-       &k1om_elf64_vec,
-       &k1om_elf64_fbsd_vec,
-       &l1om_elf64_vec,
-       &l1om_elf64_fbsd_vec,
-#endif
-
        &lm32_elf32_vec,
 
        &m32c_elf32_vec,
@@ -1219,6 +1220,8 @@ static const bfd_target * const _bfd_target_vector[] =
 
        &or1k_elf32_vec,
 
+       &pdb_vec,
+
        &pdp11_aout_vec,
 
        &pef_vec,
@@ -1348,8 +1351,6 @@ static const bfd_target * const _bfd_target_vector[] =
        &x86_64_pei_vec,
 #endif
 
-       &xc16x_elf32_vec,
-
        &xgate_elf32_vec,
 
        &xstormy16_elf32_vec,
@@ -1365,6 +1366,7 @@ static const bfd_target * const _bfd_target_vector[] =
 #ifdef BFD64
        &loongarch_elf32_vec,
        &loongarch_elf64_vec,
+       &loongarch64_pei_vec,
 #endif
 
 #endif /* not SELECT_VECS */
@@ -1387,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
@@ -1415,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
@@ -1450,7 +1446,11 @@ const bfd_target *const *const bfd_associated_vector = _bfd_associated_vector;
 /* When there is an ambiguous match, bfd_check_format_matches puts the
    names of the matching targets in an array.  This variable is the maximum
    number of entries that the array could possibly need.  */
-const size_t _bfd_target_vector_entries = sizeof (_bfd_target_vector)/sizeof (*_bfd_target_vector);
+const size_t _bfd_target_vector_entries = ARRAY_SIZE (_bfd_target_vector);
+
+/* A place to stash a warning from _bfd_check_format.  */
+static struct per_xvec_message *per_xvec_warn[ARRAY_SIZE (_bfd_target_vector)
+                                             + 1];
 \f
 /* This array maps configuration triplets onto BFD vectors.  */
 
@@ -1470,6 +1470,61 @@ static const struct targmatch bfd_target_match[] = {
   { NULL, NULL }
 };
 
+/*
+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
+       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.  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.
+*/
+
+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;
+  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.  */
 
 static const bfd_target *
@@ -1797,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";