From 0e3c1eebb22e0ade28b619fb41f42d66ed6fb145 Mon Sep 17 00:00:00 2001
From: Alan Modra <amodra@gmail.com>
Date: Fri, 27 May 2022 12:37:21 +0930
Subject: [PATCH] Remove use of bfd_uint64_t and similar

Requiring C99 means that uses of bfd_uint64_t can be replaced with
uint64_t, and similarly for bfd_int64_t, BFD_HOST_U_64_BIT, and
BFD_HOST_64_BIT.  This patch does that, removes #ifdef BFD_HOST_*
and tidies a few places that print 64-bit values.

Upstream-Status: Backport [https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=0e3c1eebb22e0ade28b619fb41f42d66ed6fb145]

CVE: CVE-2023-1579

Signed-off-by: Yash Shinde <Yash.Shinde@windriver.com>

---
 bfd/aix386-core.c       |  6 +--
 bfd/bfd-in.h            | 24 ++++++------
 bfd/bfd-in2.h           | 36 +++++++++---------
 bfd/coff-rs6000.c       | 10 +----
 bfd/coff-x86_64.c       |  2 +-
 bfd/cpu-ia64-opc.c      | 22 +++++------
 bfd/dwarf2.c            | 83 ++++++++++++++++++++---------------------
 bfd/elf32-score.c       | 16 ++++----
 bfd/elf64-ia64-vms.c    |  8 ++--
 bfd/elflink.c           | 16 +-------
 bfd/elfxx-ia64.c        |  6 +--
 bfd/hppabsd-core.c      |  6 +--
 bfd/hpux-core.c         |  6 +--
 bfd/irix-core.c         |  6 +--
 bfd/libbfd.c            | 65 +++++++++-----------------------
 bfd/mach-o.c            |  2 +-
 bfd/mach-o.h            |  8 ++--
 bfd/netbsd-core.c       |  6 +--
 bfd/osf-core.c          |  6 +--
 bfd/ptrace-core.c       |  6 +--
 bfd/sco5-core.c         |  6 +--
 bfd/targets.c           | 12 +++---
 bfd/trad-core.c         |  6 +--
 bfd/vms-alpha.c         |  2 +-
 binutils/nm.c           | 49 +++---------------------
 binutils/od-macho.c     | 50 ++++++++-----------------
 binutils/prdbg.c        | 39 +++----------------
 binutils/readelf.c      | 21 +++++------
 gas/config/tc-arm.c     | 28 ++++----------
 gas/config/tc-csky.c    | 10 ++---
 gas/config/tc-sparc.c   | 35 +++++++++--------
 gas/config/tc-tilegx.c  | 20 +++++-----
 gas/config/tc-tilepro.c | 20 +++++-----
 gas/config/tc-z80.c     |  8 ++--
 gas/config/te-vms.c     |  2 +-
 gas/config/te-vms.h     |  2 +-
 gdb/findcmd.c           |  2 +-
 gdb/tilegx-tdep.c       |  2 +-
 gprof/gmon_io.c         | 44 ++++++----------------
 include/elf/nfp.h       |  2 +-
 include/opcode/csky.h   | 62 +++++++++++++++---------------
 include/opcode/ia64.h   |  2 +-
 opcodes/csky-dis.c      |  2 +-
 opcodes/csky-opc.h      |  4 +-
 opcodes/ia64-dis.c      |  2 +-
 45 files changed, 297 insertions(+), 475 deletions(-)

diff --git a/bfd/aix386-core.c b/bfd/aix386-core.c
index 3443e49ed46..977a6bd1fb4 100644
--- a/bfd/aix386-core.c
+++ b/bfd/aix386-core.c
@@ -220,9 +220,9 @@ swap_abort (void)
 #define	NO_GET ((bfd_vma (*) (const void *)) swap_abort)
 #define	NO_PUT ((void (*) (bfd_vma, void *)) swap_abort)
 #define	NO_GETS ((bfd_signed_vma (*) (const void *)) swap_abort)
-#define	NO_GET64 ((bfd_uint64_t (*) (const void *)) swap_abort)
-#define	NO_PUT64 ((void (*) (bfd_uint64_t, void *)) swap_abort)
-#define	NO_GETS64 ((bfd_int64_t (*) (const void *)) swap_abort)
+#define	NO_GET64 ((uint64_t (*) (const void *)) swap_abort)
+#define	NO_PUT64 ((void (*) (uint64_t, void *)) swap_abort)
+#define	NO_GETS64 ((int64_t (*) (const void *)) swap_abort)

 const bfd_target core_aix386_vec =
 {
diff --git a/bfd/bfd-in.h b/bfd/bfd-in.h
index a1c4bf139fc..09c5728e944 100644
--- a/bfd/bfd-in.h
+++ b/bfd/bfd-in.h
@@ -116,10 +116,10 @@ typedef struct bfd bfd;
  #error No 64 bit integer type available
 #endif /* ! defined (BFD_HOST_64_BIT) */

-typedef BFD_HOST_U_64_BIT bfd_vma;
-typedef BFD_HOST_64_BIT bfd_signed_vma;
-typedef BFD_HOST_U_64_BIT bfd_size_type;
-typedef BFD_HOST_U_64_BIT symvalue;
+typedef uint64_t bfd_vma;
+typedef int64_t bfd_signed_vma;
+typedef uint64_t bfd_size_type;
+typedef uint64_t symvalue;

 #if BFD_HOST_64BIT_LONG
 #define BFD_VMA_FMT "l"
@@ -447,10 +447,10 @@ extern bool bfd_record_phdr

 /* Byte swapping routines.  */

-bfd_uint64_t bfd_getb64 (const void *);
-bfd_uint64_t bfd_getl64 (const void *);
-bfd_int64_t bfd_getb_signed_64 (const void *);
-bfd_int64_t bfd_getl_signed_64 (const void *);
+uint64_t bfd_getb64 (const void *);
+uint64_t bfd_getl64 (const void *);
+int64_t bfd_getb_signed_64 (const void *);
+int64_t bfd_getl_signed_64 (const void *);
 bfd_vma bfd_getb32 (const void *);
 bfd_vma bfd_getl32 (const void *);
 bfd_signed_vma bfd_getb_signed_32 (const void *);
@@ -459,8 +459,8 @@ bfd_vma bfd_getb16 (const void *);
 bfd_vma bfd_getl16 (const void *);
 bfd_signed_vma bfd_getb_signed_16 (const void *);
 bfd_signed_vma bfd_getl_signed_16 (const void *);
-void bfd_putb64 (bfd_uint64_t, void *);
-void bfd_putl64 (bfd_uint64_t, void *);
+void bfd_putb64 (uint64_t, void *);
+void bfd_putl64 (uint64_t, void *);
 void bfd_putb32 (bfd_vma, void *);
 void bfd_putl32 (bfd_vma, void *);
 void bfd_putb24 (bfd_vma, void *);
@@ -470,8 +470,8 @@ void bfd_putl16 (bfd_vma, void *);

 /* Byte swapping routines which take size and endiannes as arguments.  */

-bfd_uint64_t bfd_get_bits (const void *, int, bool);
-void bfd_put_bits (bfd_uint64_t, void *, int, bool);
+uint64_t bfd_get_bits (const void *, int, bool);
+void bfd_put_bits (uint64_t, void *, int, bool);


 /* mmap hacks */
diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index 50e26fc691d..d50885e76cf 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -123,10 +123,10 @@ typedef struct bfd bfd;
  #error No 64 bit integer type available
 #endif /* ! defined (BFD_HOST_64_BIT) */

-typedef BFD_HOST_U_64_BIT bfd_vma;
-typedef BFD_HOST_64_BIT bfd_signed_vma;
-typedef BFD_HOST_U_64_BIT bfd_size_type;
-typedef BFD_HOST_U_64_BIT symvalue;
+typedef uint64_t bfd_vma;
+typedef int64_t bfd_signed_vma;
+typedef uint64_t bfd_size_type;
+typedef uint64_t symvalue;

 #if BFD_HOST_64BIT_LONG
 #define BFD_VMA_FMT "l"
@@ -454,10 +454,10 @@ extern bool bfd_record_phdr

 /* Byte swapping routines.  */

-bfd_uint64_t bfd_getb64 (const void *);
-bfd_uint64_t bfd_getl64 (const void *);
-bfd_int64_t bfd_getb_signed_64 (const void *);
-bfd_int64_t bfd_getl_signed_64 (const void *);
+uint64_t bfd_getb64 (const void *);
+uint64_t bfd_getl64 (const void *);
+int64_t bfd_getb_signed_64 (const void *);
+int64_t bfd_getl_signed_64 (const void *);
 bfd_vma bfd_getb32 (const void *);
 bfd_vma bfd_getl32 (const void *);
 bfd_signed_vma bfd_getb_signed_32 (const void *);
@@ -466,8 +466,8 @@ bfd_vma bfd_getb16 (const void *);
 bfd_vma bfd_getl16 (const void *);
 bfd_signed_vma bfd_getb_signed_16 (const void *);
 bfd_signed_vma bfd_getl_signed_16 (const void *);
-void bfd_putb64 (bfd_uint64_t, void *);
-void bfd_putl64 (bfd_uint64_t, void *);
+void bfd_putb64 (uint64_t, void *);
+void bfd_putl64 (uint64_t, void *);
 void bfd_putb32 (bfd_vma, void *);
 void bfd_putl32 (bfd_vma, void *);
 void bfd_putb24 (bfd_vma, void *);
@@ -477,8 +477,8 @@ void bfd_putl16 (bfd_vma, void *);

 /* Byte swapping routines which take size and endiannes as arguments.  */

-bfd_uint64_t bfd_get_bits (const void *, int, bool);
-void bfd_put_bits (bfd_uint64_t, void *, int, bool);
+uint64_t bfd_get_bits (const void *, int, bool);
+void bfd_put_bits (uint64_t, void *, int, bool);


 /* mmap hacks */
@@ -7416,9 +7416,9 @@ typedef struct bfd_target
   /* 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 *);
@@ -7427,9 +7427,9 @@ typedef struct bfd_target
   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 *);
diff --git a/bfd/coff-rs6000.c b/bfd/coff-rs6000.c
index 8819187ab42..48ce5c0516b 100644
--- a/bfd/coff-rs6000.c
+++ b/bfd/coff-rs6000.c
@@ -1890,18 +1890,12 @@ xcoff_write_armap_old (bfd *abfd, unsigned int elength ATTRIBUTE_UNUSED,
 }

 static char buff20[XCOFFARMAGBIG_ELEMENT_SIZE + 1];
-#if BFD_HOST_64BIT_LONG
-#define FMT20  "%-20ld"
-#elif defined (__MSVCRT__)
-#define FMT20  "%-20I64d"
-#else
-#define FMT20  "%-20lld"
-#endif
+#define FMT20  "%-20" PRId64
 #define FMT12  "%-12d"
 #define FMT12_OCTAL  "%-12o"
 #define FMT4  "%-4d"
 #define PRINT20(d, v) \
-  sprintf (buff20, FMT20, (bfd_uint64_t)(v)), \
+  sprintf (buff20, FMT20, (uint64_t) (v)), \
   memcpy ((void *) (d), buff20, 20)

 #define PRINT12(d, v) \
diff --git a/bfd/coff-x86_64.c b/bfd/coff-x86_64.c
index e8e16d3ce4b..cf339c93215 100644
--- a/bfd/coff-x86_64.c
+++ b/bfd/coff-x86_64.c
@@ -201,7 +201,7 @@ coff_amd64_reloc (bfd *abfd,

 	case 4:
 	  {
-	    bfd_uint64_t x = bfd_get_64 (abfd, addr);
+	    uint64_t x = bfd_get_64 (abfd, addr);
 	    DOIT (x);
 	    bfd_put_64 (abfd, x, addr);
 	  }
diff --git a/bfd/cpu-ia64-opc.c b/bfd/cpu-ia64-opc.c
index e2b5c2694b6..01e3c3f476a 100644
--- a/bfd/cpu-ia64-opc.c
+++ b/bfd/cpu-ia64-opc.c
@@ -99,14 +99,14 @@ ins_immu (const struct ia64_operand *self, ia64_insn value, ia64_insn *code)
 static const char*
 ext_immu (const struct ia64_operand *self, ia64_insn code, ia64_insn *valuep)
 {
-  BFD_HOST_U_64_BIT value = 0;
+  uint64_t value = 0;
   int i, bits = 0, total = 0;

   for (i = 0; i < NELEMS (self->field) && self->field[i].bits; ++i)
     {
       bits = self->field[i].bits;
       value |= ((code >> self->field[i].shift)
-		& ((((BFD_HOST_U_64_BIT) 1) << bits) - 1)) << total;
+		& (((uint64_t) 1 << bits) - 1)) << total;
       total += bits;
     }
   *valuep = value;
@@ -161,7 +161,7 @@ static const char*
 ins_imms_scaled (const struct ia64_operand *self, ia64_insn value,
 		 ia64_insn *code, int scale)
 {
-  BFD_HOST_64_BIT svalue = value, sign_bit = 0;
+  int64_t svalue = value, sign_bit = 0;
   ia64_insn new_insn = 0;
   int i;

@@ -186,17 +186,17 @@ ext_imms_scaled (const struct ia64_operand *self, ia64_insn code,
 		 ia64_insn *valuep, int scale)
 {
   int i, bits = 0, total = 0;
-  BFD_HOST_U_64_BIT val = 0, sign;
+  uint64_t val = 0, sign;

   for (i = 0; i < NELEMS (self->field) && self->field[i].bits; ++i)
     {
       bits = self->field[i].bits;
       val |= ((code >> self->field[i].shift)
-	      & ((((BFD_HOST_U_64_BIT) 1) << bits) - 1)) << total;
+	      & (((uint64_t) 1 << bits) - 1)) << total;
       total += bits;
     }
   /* sign extend: */
-  sign = (BFD_HOST_U_64_BIT) 1 << (total - 1);
+  sign = (uint64_t) 1 << (total - 1);
   val = (val ^ sign) - sign;

   *valuep = val << scale;
@@ -312,7 +312,7 @@ static const char*
 ins_cnt (const struct ia64_operand *self, ia64_insn value, ia64_insn *code)
 {
   --value;
-  if (value >= ((BFD_HOST_U_64_BIT) 1) << self->field[0].bits)
+  if (value >= (uint64_t) 1 << self->field[0].bits)
     return "count out of range";

   *code |= value << self->field[0].shift;
@@ -323,7 +323,7 @@ static const char*
 ext_cnt (const struct ia64_operand *self, ia64_insn code, ia64_insn *valuep)
 {
   *valuep = ((code >> self->field[0].shift)
-	     & ((((BFD_HOST_U_64_BIT) 1) << self->field[0].bits) - 1)) + 1;
+	     & (((uint64_t) 1 << self->field[0].bits) - 1)) + 1;
   return 0;
 }

@@ -421,8 +421,8 @@ ext_strd5b (const struct ia64_operand *self, ia64_insn code,
 static const char*
 ins_inc3 (const struct ia64_operand *self, ia64_insn value, ia64_insn *code)
 {
-  BFD_HOST_64_BIT val = value;
-  BFD_HOST_U_64_BIT sign = 0;
+  int64_t val = value;
+  uint64_t sign = 0;

   if (val < 0)
     {
@@ -444,7 +444,7 @@ ins_inc3 (const struct ia64_operand *self, ia64_insn value, ia64_insn *code)
 static const char*
 ext_inc3 (const struct ia64_operand *self, ia64_insn code, ia64_insn *valuep)
 {
-  BFD_HOST_64_BIT val;
+  int64_t val;
   int negate;

   val = (code >> self->field[0].shift) & 0x7;
diff --git a/bfd/dwarf2.c b/bfd/dwarf2.c
index 45e286754e4..6a728fc38b0 100644
--- a/bfd/dwarf2.c
+++ b/bfd/dwarf2.c
@@ -63,8 +63,8 @@ struct attribute
   {
     char *str;
     struct dwarf_block *blk;
-    bfd_uint64_t val;
-    bfd_int64_t sval;
+    uint64_t val;
+    int64_t sval;
   }
   u;
 };
@@ -632,12 +632,12 @@ lookup_info_hash_table (struct info_hash_table *hash_table, const char *key)
    the located section does not contain at least OFFSET bytes.  */

 static bool
-read_section (bfd *	      abfd,
+read_section (bfd *abfd,
 	      const struct dwarf_debug_section *sec,
-	      asymbol **      syms,
-	      bfd_uint64_t    offset,
-	      bfd_byte **     section_buffer,
-	      bfd_size_type * section_size)
+	      asymbol **syms,
+	      uint64_t offset,
+	      bfd_byte **section_buffer,
+	      bfd_size_type *section_size)
 {
   const char *section_name = sec->uncompressed_name;
   bfd_byte *contents = *section_buffer;
@@ -848,7 +848,7 @@ read_indirect_string (struct comp_unit *unit,
 		      bfd_byte **ptr,
 		      bfd_byte *buf_end)
 {
-  bfd_uint64_t offset;
+  uint64_t offset;
   struct dwarf2_debug *stash = unit->stash;
   struct dwarf2_debug_file *file = unit->file;
   char *str;
@@ -882,7 +882,7 @@ read_indirect_line_string (struct comp_unit *unit,
 			   bfd_byte **ptr,
 			   bfd_byte *buf_end)
 {
-  bfd_uint64_t offset;
+  uint64_t offset;
   struct dwarf2_debug *stash = unit->stash;
   struct dwarf2_debug_file *file = unit->file;
   char *str;
@@ -919,7 +919,7 @@ read_alt_indirect_string (struct comp_unit *unit,
 			  bfd_byte **ptr,
 			  bfd_byte *buf_end)
 {
-  bfd_uint64_t offset;
+  uint64_t offset;
   struct dwarf2_debug *stash = unit->stash;
   char *str;

@@ -975,8 +975,7 @@ read_alt_indirect_string (struct comp_unit *unit,
    or NULL upon failure.  */

 static bfd_byte *
-read_alt_indirect_ref (struct comp_unit * unit,
-		       bfd_uint64_t       offset)
+read_alt_indirect_ref (struct comp_unit *unit, uint64_t offset)
 {
   struct dwarf2_debug *stash = unit->stash;

@@ -1012,7 +1011,7 @@ read_alt_indirect_ref (struct comp_unit * unit,
   return stash->alt.dwarf_info_buffer + offset;
 }

-static bfd_uint64_t
+static uint64_t
 read_address (struct comp_unit *unit, bfd_byte **ptr, bfd_byte *buf_end)
 {
   bfd_byte *buf = *ptr;
@@ -1131,7 +1130,7 @@ del_abbrev (void *p)
    in a hash table.  */

 static struct abbrev_info**
-read_abbrevs (bfd *abfd, bfd_uint64_t offset, struct dwarf2_debug *stash,
+read_abbrevs (bfd *abfd, uint64_t offset, struct dwarf2_debug *stash,
 	      struct dwarf2_debug_file *file)
 {
   struct abbrev_info **abbrevs;
@@ -1356,8 +1355,7 @@ is_addrx_form (enum dwarf_form form)
 /* Returns the address in .debug_addr section using DW_AT_addr_base.
    Used to implement DW_FORM_addrx*.  */
 static bfd_vma
-read_indexed_address (bfd_uint64_t idx,
-		      struct comp_unit *unit)
+read_indexed_address (uint64_t idx, struct comp_unit *unit)
 {
   struct dwarf2_debug *stash = unit->stash;
   struct dwarf2_debug_file *file = unit->file;
@@ -1383,8 +1381,7 @@ read_indexed_address (bfd_uint64_t idx,
 /* Returns the string using DW_AT_str_offsets_base.
    Used to implement DW_FORM_strx*.  */
 static const char *
-read_indexed_string (bfd_uint64_t idx,
-		     struct comp_unit *unit)
+read_indexed_string (uint64_t idx, struct comp_unit *unit)
 {
   struct dwarf2_debug *stash = unit->stash;
   struct dwarf2_debug_file *file = unit->file;
@@ -1717,39 +1714,39 @@ struct line_info_table
 struct funcinfo
 {
   /* Pointer to previous function in list of all functions.  */
-  struct funcinfo *	prev_func;
+  struct funcinfo *prev_func;
   /* Pointer to function one scope higher.  */
-  struct funcinfo *	caller_func;
+  struct funcinfo *caller_func;
   /* Source location file name where caller_func inlines this func.  */
-  char *		caller_file;
+  char *caller_file;
   /* Source location file name.  */
-  char *		file;
+  char *file;
   /* Source location line number where caller_func inlines this func.  */
-  int			caller_line;
+  int caller_line;
   /* Source location line number.  */
-  int			line;
-  int			tag;
-  bool			is_linkage;
-  const char *		name;
-  struct arange		arange;
+  int line;
+  int tag;
+  bool is_linkage;
+  const char *name;
+  struct arange arange;
   /* Where the symbol is defined.  */
-  asection *		sec;
+  asection *sec;
   /* The offset of the funcinfo from the start of the unit.  */
-  bfd_uint64_t          unit_offset;
+  uint64_t unit_offset;
 };

 struct lookup_funcinfo
 {
   /* Function information corresponding to this lookup table entry.  */
-  struct funcinfo *	funcinfo;
+  struct funcinfo *funcinfo;

   /* The lowest address for this specific function.  */
-  bfd_vma		low_addr;
+  bfd_vma low_addr;

   /* The highest address of this function before the lookup table is sorted.
      The highest address of all prior functions after the lookup table is
      sorted, which is used for binary search.  */
-  bfd_vma		high_addr;
+  bfd_vma high_addr;
   /* Index of this function, used to ensure qsort is stable.  */
   unsigned int idx;
 };
@@ -1759,7 +1756,7 @@ struct varinfo
   /* Pointer to previous variable in list of all variables.  */
   struct varinfo *prev_var;
   /* The offset of the varinfo from the start of the unit.  */
-  bfd_uint64_t unit_offset;
+  uint64_t unit_offset;
   /* Source location file name.  */
   char *file;
   /* Source location line number.  */
@@ -3335,7 +3332,7 @@ find_abstract_instance (struct comp_unit *unit,
   bfd_byte *info_ptr_end;
   unsigned int abbrev_number, i;
   struct abbrev_info *abbrev;
-  bfd_uint64_t die_ref = attr_ptr->u.val;
+  uint64_t die_ref = attr_ptr->u.val;
   struct attribute attr;
   const char *name = NULL;

@@ -3549,7 +3546,7 @@ find_abstract_instance (struct comp_unit *unit,

 static bool
 read_ranges (struct comp_unit *unit, struct arange *arange,
-	     struct trie_node **trie_root, bfd_uint64_t offset)
+	     struct trie_node **trie_root, uint64_t offset)
 {
   bfd_byte *ranges_ptr;
   bfd_byte *ranges_end;
@@ -3594,7 +3591,7 @@ read_ranges (struct comp_unit *unit, struct arange *arange,

 static bool
 read_rnglists (struct comp_unit *unit, struct arange *arange,
-	       struct trie_node **trie_root, bfd_uint64_t offset)
+	       struct trie_node **trie_root, uint64_t offset)
 {
   bfd_byte *rngs_ptr;
   bfd_byte *rngs_end;
@@ -3675,7 +3672,7 @@ read_rnglists (struct comp_unit *unit, struct arange *arange,

 static bool
 read_rangelist (struct comp_unit *unit, struct arange *arange,
-		struct trie_node **trie_root, bfd_uint64_t offset)
+		struct trie_node **trie_root, uint64_t offset)
 {
   if (unit->version <= 4)
     return read_ranges (unit, arange, trie_root, offset);
@@ -3684,7 +3681,7 @@ read_rangelist (struct comp_unit *unit, struct arange *arange,
 }

 static struct funcinfo *
-lookup_func_by_offset (bfd_uint64_t offset, struct funcinfo * table)
+lookup_func_by_offset (uint64_t offset, struct funcinfo * table)
 {
   for (; table != NULL; table = table->prev_func)
     if (table->unit_offset == offset)
@@ -3693,7 +3690,7 @@ lookup_func_by_offset (bfd_uint64_t offset, struct funcinfo * table)
 }

 static struct varinfo *
-lookup_var_by_offset (bfd_uint64_t offset, struct varinfo * table)
+lookup_var_by_offset (uint64_t offset, struct varinfo * table)
 {
   while (table)
     {
@@ -3775,7 +3772,7 @@ scan_unit_for_symbols (struct comp_unit *unit)
       struct abbrev_info *abbrev;
       struct funcinfo *func;
       struct varinfo *var;
-      bfd_uint64_t current_offset;
+      uint64_t current_offset;

       /* PR 17512: file: 9f405d9d.  */
       if (info_ptr >= info_ptr_end)
@@ -3909,7 +3906,7 @@ scan_unit_for_symbols (struct comp_unit *unit)
       bfd_vma low_pc = 0;
       bfd_vma high_pc = 0;
       bool high_pc_relative = false;
-      bfd_uint64_t current_offset;
+      uint64_t current_offset;

       /* PR 17512: file: 9f405d9d.  */
       if (info_ptr >= info_ptr_end)
@@ -4259,7 +4256,7 @@ parse_comp_unit (struct dwarf2_debug *stash,
 {
   struct comp_unit* unit;
   unsigned int version;
-  bfd_uint64_t abbrev_offset = 0;
+  uint64_t abbrev_offset = 0;
   /* Initialize it just to avoid a GCC false warning.  */
   unsigned int addr_size = -1;
   struct abbrev_info** abbrevs;
diff --git a/bfd/elf32-score.c b/bfd/elf32-score.c
index c868707347c..5bc78d523ea 100644
--- a/bfd/elf32-score.c
+++ b/bfd/elf32-score.c
@@ -230,14 +230,14 @@ static bfd_vma
 score3_bfd_getl48 (const void *p)
 {
   const bfd_byte *addr = p;
-  bfd_uint64_t v;
-
-  v = (bfd_uint64_t) addr[4];
-  v |= (bfd_uint64_t) addr[5] << 8;
-  v |= (bfd_uint64_t) addr[2] << 16;
-  v |= (bfd_uint64_t) addr[3] << 24;
-  v |= (bfd_uint64_t) addr[0] << 32;
-  v |= (bfd_uint64_t) addr[1] << 40;
+  uint64_t v;
+
+  v = (uint64_t) addr[4];
+  v |= (uint64_t) addr[5] << 8;
+  v |= (uint64_t) addr[2] << 16;
+  v |= (uint64_t) addr[3] << 24;
+  v |= (uint64_t) addr[0] << 32;
+  v |= (uint64_t) addr[1] << 40;
   return v;
 }

diff --git a/bfd/elf64-ia64-vms.c b/bfd/elf64-ia64-vms.c
index 59cc6b6fe85..4d8f98550a3 100644
--- a/bfd/elf64-ia64-vms.c
+++ b/bfd/elf64-ia64-vms.c
@@ -179,7 +179,7 @@ struct elf64_ia64_vms_obj_tdata
   struct elf_obj_tdata root;

   /* Ident for shared library.  */
-  bfd_uint64_t ident;
+  uint64_t ident;

   /* Used only during link: offset in the .fixups section for this bfd.  */
   bfd_vma fixups_off;
@@ -2791,7 +2791,7 @@ elf64_ia64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
       if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_IDENT, 0))
 	return false;
       if (!_bfd_elf_add_dynamic_entry (info, DT_IA_64_VMS_LINKTIME,
-				       (((bfd_uint64_t)time_hi) << 32)
+				       ((uint64_t) time_hi << 32)
 				       + time_lo))
 	return false;

@@ -4720,7 +4720,7 @@ elf64_vms_close_and_cleanup (bfd *abfd)
       if ((isize & 7) != 0)
 	{
 	  int ishort = 8 - (isize & 7);
-	  bfd_uint64_t pad = 0;
+	  uint64_t pad = 0;

 	  bfd_seek (abfd, isize, SEEK_SET);
 	  bfd_bwrite (&pad, ishort, abfd);
@@ -4853,7 +4853,7 @@ elf64_vms_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
 	  bed->s->swap_dyn_in (abfd, extdyn, &dyn);
 	  if (dyn.d_tag == DT_IA_64_VMS_IDENT)
 	    {
-	      bfd_uint64_t tagv = dyn.d_un.d_val;
+	      uint64_t tagv = dyn.d_un.d_val;
 	      elf_ia64_vms_ident (abfd) = tagv;
 	      break;
 	    }
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 96eb36aa5bf..fc3a335c72d 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -6354,15 +6354,11 @@ compute_bucket_count (struct bfd_link_info *info ATTRIBUTE_UNUSED,
   size_t best_size = 0;
   unsigned long int i;

-  /* We have a problem here.  The following code to optimize the table
-     size requires an integer type with more the 32 bits.  If
-     BFD_HOST_U_64_BIT is set we know about such a type.  */
-#ifdef BFD_HOST_U_64_BIT
   if (info->optimize)
     {
       size_t minsize;
       size_t maxsize;
-      BFD_HOST_U_64_BIT best_chlen = ~((BFD_HOST_U_64_BIT) 0);
+      uint64_t best_chlen = ~((uint64_t) 0);
       bfd *dynobj = elf_hash_table (info)->dynobj;
       size_t dynsymcount = elf_hash_table (info)->dynsymcount;
       const struct elf_backend_data *bed = get_elf_backend_data (dynobj);
@@ -6399,7 +6395,7 @@ compute_bucket_count (struct bfd_link_info *info ATTRIBUTE_UNUSED,
       for (i = minsize; i < maxsize; ++i)
 	{
 	  /* Walk through the array of hashcodes and count the collisions.  */
-	  BFD_HOST_U_64_BIT max;
+	  uint64_t max;
 	  unsigned long int j;
 	  unsigned long int fact;

@@ -6464,11 +6460,7 @@ compute_bucket_count (struct bfd_link_info *info ATTRIBUTE_UNUSED,
       free (counts);
     }
   else
-#endif /* defined (BFD_HOST_U_64_BIT) */
     {
-      /* This is the fallback solution if no 64bit type is available or if we
-	 are not supposed to spend much time on optimizations.  We select the
-	 bucket count using a fixed set of numbers.  */
       for (i = 0; elf_buckets[i] != 0; i++)
 	{
 	  best_size = elf_buckets[i];
@@ -9354,7 +9346,6 @@ ext32b_r_offset (const void *p)
   return aval;
 }

-#ifdef BFD_HOST_64_BIT
 static bfd_vma
 ext64l_r_offset (const void *p)
 {
@@ -9398,7 +9389,6 @@ ext64b_r_offset (const void *p)
 		   | (uint64_t) a->c[7]);
   return aval;
 }
-#endif

 /* When performing a relocatable link, the input relocations are
    preserved.  But, if they reference global symbols, the indices
@@ -9502,13 +9492,11 @@ elf_link_adjust_relocs (bfd *abfd,
 	}
       else
 	{
-#ifdef BFD_HOST_64_BIT
 	  if (abfd->xvec->header_byteorder == BFD_ENDIAN_LITTLE)
 	    ext_r_off = ext64l_r_offset;
 	  else if (abfd->xvec->header_byteorder == BFD_ENDIAN_BIG)
 	    ext_r_off = ext64b_r_offset;
 	  else
-#endif
 	    abort ();
 	}

diff --git a/bfd/elfxx-ia64.c b/bfd/elfxx-ia64.c
index c126adf6890..a108324ca39 100644
--- a/bfd/elfxx-ia64.c
+++ b/bfd/elfxx-ia64.c
@@ -555,11 +555,7 @@ ia64_elf_install_value (bfd_byte *hit_addr, bfd_vma v, unsigned int r_type)
   enum ia64_opnd opnd;
   const char *err;
   size_t size = 8;
-#ifdef BFD_HOST_U_64_BIT
-  BFD_HOST_U_64_BIT val = (BFD_HOST_U_64_BIT) v;
-#else
-  bfd_vma val = v;
-#endif
+  uint64_t val = v;

   opnd = IA64_OPND_NIL;
   switch (r_type)
diff --git a/bfd/hppabsd-core.c b/bfd/hppabsd-core.c
index acfa5f69a95..d87af955838 100644
--- a/bfd/hppabsd-core.c
+++ b/bfd/hppabsd-core.c
@@ -213,9 +213,9 @@ swap_abort (void)
 #define	NO_GET ((bfd_vma (*) (const void *)) swap_abort)
 #define	NO_PUT ((void (*) (bfd_vma, void *)) swap_abort)
 #define	NO_GETS ((bfd_signed_vma (*) (const void *)) swap_abort)
-#define	NO_GET64 ((bfd_uint64_t (*) (const void *)) swap_abort)
-#define	NO_PUT64 ((void (*) (bfd_uint64_t, void *)) swap_abort)
-#define	NO_GETS64 ((bfd_int64_t (*) (const void *)) swap_abort)
+#define	NO_GET64 ((uint64_t (*) (const void *)) swap_abort)
+#define	NO_PUT64 ((void (*) (uint64_t, void *)) swap_abort)
+#define	NO_GETS64 ((int64_t (*) (const void *)) swap_abort)

 const bfd_target core_hppabsd_vec =
   {
diff --git a/bfd/hpux-core.c b/bfd/hpux-core.c
index 4f03b84909a..654532c6bb9 100644
--- a/bfd/hpux-core.c
+++ b/bfd/hpux-core.c
@@ -362,9 +362,9 @@ swap_abort (void)
 #define	NO_GET ((bfd_vma (*) (const void *)) swap_abort)
 #define	NO_PUT ((void (*) (bfd_vma, void *)) swap_abort)
 #define	NO_GETS ((bfd_signed_vma (*) (const void *)) swap_abort)
-#define	NO_GET64 ((bfd_uint64_t (*) (const void *)) swap_abort)
-#define	NO_PUT64 ((void (*) (bfd_uint64_t, void *)) swap_abort)
-#define	NO_GETS64 ((bfd_int64_t (*) (const void *)) swap_abort)
+#define	NO_GET64 ((uint64_t (*) (const void *)) swap_abort)
+#define	NO_PUT64 ((void (*) (uint64_t, void *)) swap_abort)
+#define	NO_GETS64 ((int64_t (*) (const void *)) swap_abort)

 const bfd_target core_hpux_vec =
   {
diff --git a/bfd/irix-core.c b/bfd/irix-core.c
index 694fe2e2e07..b12aef9ce8b 100644
--- a/bfd/irix-core.c
+++ b/bfd/irix-core.c
@@ -275,9 +275,9 @@ swap_abort(void)
 #define	NO_GET ((bfd_vma (*) (const void *)) swap_abort)
 #define	NO_PUT ((void (*) (bfd_vma, void *)) swap_abort)
 #define	NO_GETS ((bfd_signed_vma (*) (const void *)) swap_abort)
-#define	NO_GET64 ((bfd_uint64_t (*) (const void *)) swap_abort)
-#define	NO_PUT64 ((void (*) (bfd_uint64_t, void *)) swap_abort)
-#define	NO_GETS64 ((bfd_int64_t (*) (const void *)) swap_abort)
+#define	NO_GET64 ((uint64_t (*) (const void *)) swap_abort)
+#define	NO_PUT64 ((void (*) (uint64_t, void *)) swap_abort)
+#define	NO_GETS64 ((int64_t (*) (const void *)) swap_abort)

 const bfd_target core_irix_vec =
   {
diff --git a/bfd/libbfd.c b/bfd/libbfd.c
index 2781671ddba..d33f3416206 100644
--- a/bfd/libbfd.c
+++ b/bfd/libbfd.c
@@ -617,7 +617,7 @@ DESCRIPTION
 #define COERCE16(x) (((bfd_vma) (x) ^ 0x8000) - 0x8000)
 #define COERCE32(x) (((bfd_vma) (x) ^ 0x80000000) - 0x80000000)
 #define COERCE64(x) \
-  (((bfd_uint64_t) (x) ^ ((bfd_uint64_t) 1 << 63)) - ((bfd_uint64_t) 1 << 63))
+  (((uint64_t) (x) ^ ((uint64_t) 1 << 63)) - ((uint64_t) 1 << 63))

 bfd_vma
 bfd_getb16 (const void *p)
@@ -757,12 +757,11 @@ bfd_getl_signed_32 (const void *p)
   return COERCE32 (v);
 }

-bfd_uint64_t
-bfd_getb64 (const void *p ATTRIBUTE_UNUSED)
+uint64_t
+bfd_getb64 (const void *p)
 {
-#ifdef BFD_HOST_64_BIT
   const bfd_byte *addr = (const bfd_byte *) p;
-  bfd_uint64_t v;
+  uint64_t v;

   v  = addr[0]; v <<= 8;
   v |= addr[1]; v <<= 8;
@@ -774,18 +773,13 @@ bfd_getb64 (const void *p ATTRIBUTE_UNUSED)
   v |= addr[7];

   return v;
-#else
-  BFD_FAIL();
-  return 0;
-#endif
 }

-bfd_uint64_t
-bfd_getl64 (const void *p ATTRIBUTE_UNUSED)
+uint64_t
+bfd_getl64 (const void *p)
 {
-#ifdef BFD_HOST_64_BIT
   const bfd_byte *addr = (const bfd_byte *) p;
-  bfd_uint64_t v;
+  uint64_t v;

   v  = addr[7]; v <<= 8;
   v |= addr[6]; v <<= 8;
@@ -797,19 +791,13 @@ bfd_getl64 (const void *p ATTRIBUTE_UNUSED)
   v |= addr[0];

   return v;
-#else
-  BFD_FAIL();
-  return 0;
-#endif
-
 }

-bfd_int64_t
-bfd_getb_signed_64 (const void *p ATTRIBUTE_UNUSED)
+int64_t
+bfd_getb_signed_64 (const void *p)
 {
-#ifdef BFD_HOST_64_BIT
   const bfd_byte *addr = (const bfd_byte *) p;
-  bfd_uint64_t v;
+  uint64_t v;

   v  = addr[0]; v <<= 8;
   v |= addr[1]; v <<= 8;
@@ -821,18 +809,13 @@ bfd_getb_signed_64 (const void *p ATTRIBUTE_UNUSED)
   v |= addr[7];

   return COERCE64 (v);
-#else
-  BFD_FAIL();
-  return 0;
-#endif
 }

-bfd_int64_t
-bfd_getl_signed_64 (const void *p ATTRIBUTE_UNUSED)
+int64_t
+bfd_getl_signed_64 (const void *p)
 {
-#ifdef BFD_HOST_64_BIT
   const bfd_byte *addr = (const bfd_byte *) p;
-  bfd_uint64_t v;
+  uint64_t v;

   v  = addr[7]; v <<= 8;
   v |= addr[6]; v <<= 8;
@@ -844,10 +827,6 @@ bfd_getl_signed_64 (const void *p ATTRIBUTE_UNUSED)
   v |= addr[0];

   return COERCE64 (v);
-#else
-  BFD_FAIL();
-  return 0;
-#endif
 }

 void
@@ -871,9 +850,8 @@ bfd_putl32 (bfd_vma data, void *p)
 }

 void
-bfd_putb64 (bfd_uint64_t data ATTRIBUTE_UNUSED, void *p ATTRIBUTE_UNUSED)
+bfd_putb64 (uint64_t data, void *p)
 {
-#ifdef BFD_HOST_64_BIT
   bfd_byte *addr = (bfd_byte *) p;
   addr[0] = (data >> (7*8)) & 0xff;
   addr[1] = (data >> (6*8)) & 0xff;
@@ -883,15 +861,11 @@ bfd_putb64 (bfd_uint64_t data ATTRIBUTE_UNUSED, void *p ATTRIBUTE_UNUSED)
   addr[5] = (data >> (2*8)) & 0xff;
   addr[6] = (data >> (1*8)) & 0xff;
   addr[7] = (data >> (0*8)) & 0xff;
-#else
-  BFD_FAIL();
-#endif
 }

 void
-bfd_putl64 (bfd_uint64_t data ATTRIBUTE_UNUSED, void *p ATTRIBUTE_UNUSED)
+bfd_putl64 (uint64_t data, void *p)
 {
-#ifdef BFD_HOST_64_BIT
   bfd_byte *addr = (bfd_byte *) p;
   addr[7] = (data >> (7*8)) & 0xff;
   addr[6] = (data >> (6*8)) & 0xff;
@@ -901,13 +875,10 @@ bfd_putl64 (bfd_uint64_t data ATTRIBUTE_UNUSED, void *p ATTRIBUTE_UNUSED)
   addr[2] = (data >> (2*8)) & 0xff;
   addr[1] = (data >> (1*8)) & 0xff;
   addr[0] = (data >> (0*8)) & 0xff;
-#else
-  BFD_FAIL();
-#endif
 }

 void
-bfd_put_bits (bfd_uint64_t data, void *p, int bits, bool big_p)
+bfd_put_bits (uint64_t data, void *p, int bits, bool big_p)
 {
   bfd_byte *addr = (bfd_byte *) p;
   int i;
@@ -926,11 +897,11 @@ bfd_put_bits (bfd_uint64_t data, void *p, int bits, bool big_p)
     }
 }

-bfd_uint64_t
+uint64_t
 bfd_get_bits (const void *p, int bits, bool big_p)
 {
   const bfd_byte *addr = (const bfd_byte *) p;
-  bfd_uint64_t data;
+  uint64_t data;
   int i;
   int bytes;

diff --git a/bfd/mach-o.c b/bfd/mach-o.c
index e32b7873cef..9f3f1f13e4e 100644
--- a/bfd/mach-o.c
+++ b/bfd/mach-o.c
@@ -4773,7 +4773,7 @@ bfd_mach_o_read_source_version (bfd *abfd, bfd_mach_o_load_command *command)
 {
   bfd_mach_o_source_version_command *cmd = &command->command.source_version;
   struct mach_o_source_version_command_external raw;
-  bfd_uint64_t ver;
+  uint64_t ver;

   if (command->len < sizeof (raw) + 8)
     return false;
diff --git a/bfd/mach-o.h b/bfd/mach-o.h
index 5a068d8d970..f7418ad8d40 100644
--- a/bfd/mach-o.h
+++ b/bfd/mach-o.h
@@ -545,8 +545,8 @@ bfd_mach_o_encryption_info_command;

 typedef struct bfd_mach_o_main_command
 {
-  bfd_uint64_t entryoff;
-  bfd_uint64_t stacksize;
+  uint64_t entryoff;
+  uint64_t stacksize;
 }
 bfd_mach_o_main_command;

@@ -563,8 +563,8 @@ bfd_mach_o_source_version_command;
 typedef struct bfd_mach_o_note_command
 {
   char data_owner[16];
-  bfd_uint64_t offset;
-  bfd_uint64_t size;
+  uint64_t offset;
+  uint64_t size;
 }
 bfd_mach_o_note_command;

diff --git a/bfd/netbsd-core.c b/bfd/netbsd-core.c
index cb215937da6..ffc8e50842c 100644
--- a/bfd/netbsd-core.c
+++ b/bfd/netbsd-core.c
@@ -257,9 +257,9 @@ swap_abort (void)
 #define	NO_GET ((bfd_vma (*) (const void *)) swap_abort)
 #define	NO_PUT ((void (*) (bfd_vma, void *)) swap_abort)
 #define	NO_GETS ((bfd_signed_vma (*) (const void *)) swap_abort)
-#define	NO_GET64 ((bfd_uint64_t (*) (const void *)) swap_abort)
-#define	NO_PUT64 ((void (*) (bfd_uint64_t, void *)) swap_abort)
-#define	NO_GETS64 ((bfd_int64_t (*) (const void *)) swap_abort)
+#define	NO_GET64 ((uint64_t (*) (const void *)) swap_abort)
+#define	NO_PUT64 ((void (*) (uint64_t, void *)) swap_abort)
+#define	NO_GETS64 ((int64_t (*) (const void *)) swap_abort)

 const bfd_target core_netbsd_vec =
   {
diff --git a/bfd/osf-core.c b/bfd/osf-core.c
index 09a04a07624..04434b2045c 100644
--- a/bfd/osf-core.c
+++ b/bfd/osf-core.c
@@ -169,9 +169,9 @@ swap_abort (void)
 #define	NO_GET ((bfd_vma (*) (const void *)) swap_abort)
 #define	NO_PUT ((void (*) (bfd_vma, void *)) swap_abort)
 #define	NO_GETS ((bfd_signed_vma (*) (const void *)) swap_abort)
-#define	NO_GET64 ((bfd_uint64_t (*) (const void *)) swap_abort)
-#define	NO_PUT64 ((void (*) (bfd_uint64_t, void *)) swap_abort)
-#define	NO_GETS64 ((bfd_int64_t (*) (const void *)) swap_abort)
+#define	NO_GET64 ((uint64_t (*) (const void *)) swap_abort)
+#define	NO_PUT64 ((void (*) (uint64_t, void *)) swap_abort)
+#define	NO_GETS64 ((int64_t (*) (const void *)) swap_abort)

 const bfd_target core_osf_vec =
   {
diff --git a/bfd/ptrace-core.c b/bfd/ptrace-core.c
index 3d077d21200..c4afffbfb95 100644
--- a/bfd/ptrace-core.c
+++ b/bfd/ptrace-core.c
@@ -160,9 +160,9 @@ swap_abort (void)
 #define	NO_GET ((bfd_vma (*) (const void *)) swap_abort)
 #define	NO_PUT ((void (*) (bfd_vma, void *)) swap_abort)
 #define	NO_GETS ((bfd_signed_vma (*) (const void *)) swap_abort)
-#define	NO_GET64 ((bfd_uint64_t (*) (const void *)) swap_abort)
-#define	NO_PUT64 ((void (*) (bfd_uint64_t, void *)) swap_abort)
-#define	NO_GETS64 ((bfd_int64_t (*) (const void *)) swap_abort)
+#define	NO_GET64 ((uint64_t (*) (const void *)) swap_abort)
+#define	NO_PUT64 ((void (*) (uint64_t, void *)) swap_abort)
+#define	NO_GETS64 ((int64_t (*) (const void *)) swap_abort)

 const bfd_target core_ptrace_vec =
   {
diff --git a/bfd/sco5-core.c b/bfd/sco5-core.c
index d1f80c9079f..7807ac86a65 100644
--- a/bfd/sco5-core.c
+++ b/bfd/sco5-core.c
@@ -340,9 +340,9 @@ swap_abort (void)
 #define	NO_GET ((bfd_vma (*) (const void *)) swap_abort)
 #define	NO_PUT ((void (*) (bfd_vma, void *)) swap_abort)
 #define	NO_GETS ((bfd_signed_vma (*) (const void *)) swap_abort)
-#define	NO_GET64 ((bfd_uint64_t (*) (const void *)) swap_abort)
-#define	NO_PUT64 ((void (*) (bfd_uint64_t, void *)) swap_abort)
-#define	NO_GETS64 ((bfd_int64_t (*) (const void *)) swap_abort)
+#define	NO_GET64 ((uint64_t (*) (const void *)) swap_abort)
+#define	NO_PUT64 ((void (*) (uint64_t, void *)) swap_abort)
+#define	NO_GETS64 ((int64_t (*) (const void *)) swap_abort)

 const bfd_target core_sco5_vec =
   {
diff --git a/bfd/targets.c b/bfd/targets.c
index 05dd8236d91..f44b5c67724 100644
--- a/bfd/targets.c
+++ b/bfd/targets.c
@@ -226,9 +226,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 +237,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 *);
diff --git a/bfd/trad-core.c b/bfd/trad-core.c
index 92a279b6a72..8e9ee0d6667 100644
--- a/bfd/trad-core.c
+++ b/bfd/trad-core.c
@@ -249,9 +249,9 @@ swap_abort (void)
 #define	NO_GET ((bfd_vma (*) (const void *)) swap_abort)
 #define	NO_PUT ((void (*) (bfd_vma, void *)) swap_abort)
 #define	NO_GETS ((bfd_signed_vma (*) (const void *)) swap_abort)
-#define	NO_GET64 ((bfd_uint64_t (*) (const void *)) swap_abort)
-#define	NO_PUT64 ((void (*) (bfd_uint64_t, void *)) swap_abort)
-#define	NO_GETS64 ((bfd_int64_t (*) (const void *)) swap_abort)
+#define	NO_GET64 ((uint64_t (*) (const void *)) swap_abort)
+#define	NO_PUT64 ((void (*) (uint64_t, void *)) swap_abort)
+#define	NO_GETS64 ((int64_t (*) (const void *)) swap_abort)

 const bfd_target core_trad_vec =
   {
diff --git a/bfd/vms-alpha.c b/bfd/vms-alpha.c
index 1129c98f0e2..fd0762811df 100644
--- a/bfd/vms-alpha.c
+++ b/bfd/vms-alpha.c
@@ -522,7 +522,7 @@ _bfd_vms_slurp_eisd (bfd *abfd, unsigned int offset)
       struct vms_eisd *eisd;
       unsigned int rec_size;
       unsigned int size;
-      bfd_uint64_t vaddr;
+      uint64_t vaddr;
       unsigned int flags;
       unsigned int vbn;
       char *name = NULL;
diff --git a/binutils/nm.c b/binutils/nm.c
index 60e4d850885..539c5688425 100644
--- a/binutils/nm.c
+++ b/binutils/nm.c
@@ -1557,29 +1557,15 @@ get_print_format (void)
       padding = "016";
     }

-  const char * length = "l";
-  if (print_width == 64)
-    {
-#if BFD_HOST_64BIT_LONG
-      ;
-#elif BFD_HOST_64BIT_LONG_LONG
-#ifndef __MSVCRT__
-      length = "ll";
-#else
-      length = "I64";
-#endif
-#endif
-    }
-
   const char * radix = NULL;
   switch (print_radix)
     {
-    case 8:  radix = "o"; break;
-    case 10: radix = "d"; break;
-    case 16: radix = "x"; break;
+    case 8:  radix = PRIo64; break;
+    case 10: radix = PRId64; break;
+    case 16: radix = PRIx64; break;
     }

-  return concat ("%", padding, length, radix, NULL);
+  return concat ("%", padding, radix, NULL);
 }

 static void
@@ -1874,33 +1860,8 @@ print_value (bfd *abfd ATTRIBUTE_UNUSED, bfd_vma val)
   switch (print_width)
     {
     case 32:
-      printf (print_format_string, (unsigned long) val);
-      break;
-
     case 64:
-#if BFD_HOST_64BIT_LONG || BFD_HOST_64BIT_LONG_LONG
-      printf (print_format_string, val);
-#else
-      /* We have a 64 bit value to print, but the host is only 32 bit.  */
-      if (print_radix == 16)
-	bfd_fprintf_vma (abfd, stdout, val);
-      else
-	{
-	  char buf[30];
-	  char *s;
-
-	  s = buf + sizeof buf;
-	  *--s = '\0';
-	  while (val > 0)
-	    {
-	      *--s = (val % print_radix) + '0';
-	      val /= print_radix;
-	    }
-	  while ((buf + sizeof buf - 1) - s < 16)
-	    *--s = '0';
-	  printf ("%s", s);
-	}
-#endif
+      printf (print_format_string, (uint64_t) val);
       break;

     default:
diff --git a/binutils/od-macho.c b/binutils/od-macho.c
index 56d448ac3bd..e91c87d2acf 100644
--- a/binutils/od-macho.c
+++ b/binutils/od-macho.c
@@ -283,15 +283,6 @@ bfd_mach_o_print_flags (const bfd_mach_o_xlat_name *table,
     printf ("-");
 }

-/* Print a bfd_uint64_t, using a platform independent style.  */
-
-static void
-printf_uint64 (bfd_uint64_t v)
-{
-  printf ("0x%08lx%08lx",
-	  (unsigned long)((v >> 16) >> 16), (unsigned long)(v & 0xffffffffUL));
-}
-
 static const char *
 bfd_mach_o_get_name_or_null (const bfd_mach_o_xlat_name *table,
                              unsigned long val)
@@ -1729,26 +1720,20 @@ dump_load_command (bfd *abfd, bfd_mach_o_load_command *cmd,
       }
     case BFD_MACH_O_LC_MAIN:
       {
-        bfd_mach_o_main_command *entry = &cmd->command.main;
-        printf ("   entry offset: ");
-	printf_uint64 (entry->entryoff);
-        printf ("\n"
-                "   stack size:   ");
-	printf_uint64 (entry->stacksize);
-	printf ("\n");
-        break;
+	bfd_mach_o_main_command *entry = &cmd->command.main;
+	printf ("   entry offset: %#016" PRIx64 "\n"
+		"   stack size:   %#016" PRIx64 "\n",
+		entry->entryoff, entry->stacksize);
+	break;
       }
     case BFD_MACH_O_LC_NOTE:
       {
-        bfd_mach_o_note_command *note = &cmd->command.note;
-        printf ("   data owner: %.16s\n", note->data_owner);
-        printf ("   offset:     ");
-	printf_uint64 (note->offset);
-        printf ("\n"
-                "   size:       ");
-	printf_uint64 (note->size);
-	printf ("\n");
-        break;
+	bfd_mach_o_note_command *note = &cmd->command.note;
+	printf ("   data owner: %.16s\n"
+		"   offset:     %#016" PRIx64 "\n"
+		"   size:       %#016" PRIx64 "\n",
+		note->data_owner, note->offset, note->size);
+	break;
       }
     case BFD_MACH_O_LC_BUILD_VERSION:
       dump_build_version (abfd, cmd);
@@ -2013,14 +1998,11 @@ dump_obj_compact_unwind (bfd *abfd,
 	{
 	  e = (struct mach_o_compact_unwind_64 *) p;

-	  putchar (' ');
-	  printf_uint64 (bfd_get_64 (abfd, e->start));
-	  printf (" %08lx", (unsigned long)bfd_get_32 (abfd, e->length));
-	  putchar (' ');
-	  printf_uint64 (bfd_get_64 (abfd, e->personality));
-	  putchar (' ');
-	  printf_uint64 (bfd_get_64 (abfd, e->lsda));
-	  putchar ('\n');
+	  printf (" %#016" PRIx64 " %#08x %#016" PRIx64 " %#016" PRIx64 "\n",
+		  (uint64_t) bfd_get_64 (abfd, e->start),
+		  (unsigned int) bfd_get_32 (abfd, e->length),
+		  (uint64_t) bfd_get_64 (abfd, e->personality),
+		  (uint64_t) bfd_get_64 (abfd, e->lsda));

 	  printf ("  encoding: ");
 	  dump_unwind_encoding (mdata, bfd_get_32 (abfd, e->encoding));
diff --git a/binutils/prdbg.c b/binutils/prdbg.c
index d6cbab8578b..c1e41628d26 100644
--- a/binutils/prdbg.c
+++ b/binutils/prdbg.c
@@ -485,41 +485,12 @@ pop_type (struct pr_handle *info)
 static void
 print_vma (bfd_vma vma, char *buf, bool unsignedp, bool hexp)
 {
-  if (sizeof (vma) <= sizeof (unsigned long))
-    {
-      if (hexp)
-	sprintf (buf, "0x%lx", (unsigned long) vma);
-      else if (unsignedp)
-	sprintf (buf, "%lu", (unsigned long) vma);
-      else
-	sprintf (buf, "%ld", (long) vma);
-    }
-#if BFD_HOST_64BIT_LONG_LONG
-  else if (sizeof (vma) <= sizeof (unsigned long long))
-    {
-#ifndef __MSVCRT__
-      if (hexp)
-	sprintf (buf, "0x%llx", (unsigned long long) vma);
-      else if (unsignedp)
-	sprintf (buf, "%llu", (unsigned long long) vma);
-      else
-	sprintf (buf, "%lld", (long long) vma);
-#else
-      if (hexp)
-	sprintf (buf, "0x%I64x", (unsigned long long) vma);
-      else if (unsignedp)
-	sprintf (buf, "%I64u", (unsigned long long) vma);
-      else
-	sprintf (buf, "%I64d", (long long) vma);
-#endif
-    }
-#endif
+  if (hexp)
+    sprintf (buf, "%#" PRIx64, (uint64_t) vma);
+  else if (unsignedp)
+    sprintf (buf, "%" PRIu64, (uint64_t) vma);
   else
-    {
-      buf[0] = '0';
-      buf[1] = 'x';
-      sprintf_vma (buf + 2, vma);
-    }
+    sprintf (buf, "%" PRId64, (int64_t) vma);
 }
 
 /* Start a new compilation unit.  */
diff --git a/binutils/readelf.c b/binutils/readelf.c
index c35bfc12366..4c0a2a34767 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -10729,7 +10729,7 @@ dynamic_section_parisc_val (Elf_Internal_Dyn * entry)
 /* Display a VMS time in a human readable format.  */

 static void
-print_vms_time (bfd_int64_t vmstime)
+print_vms_time (int64_t vmstime)
 {
   struct tm *tm = NULL;
   time_t unxtime;
@@ -20764,7 +20764,7 @@ print_ia64_vms_note (Elf_Internal_Note * pnote)
       /* FIXME: Generate an error if descsz > 8 ?  */

       printf ("0x%016" BFD_VMA_FMT "x\n",
-	      (bfd_vma) byte_get ((unsigned char *)pnote->descdata, 8));
+	      (bfd_vma) byte_get ((unsigned char *) pnote->descdata, 8));
       break;

     case NT_VMS_LINKTIME:
@@ -20773,8 +20773,7 @@ print_ia64_vms_note (Elf_Internal_Note * pnote)
 	goto desc_size_fail;
       /* FIXME: Generate an error if descsz > 8 ?  */

-      print_vms_time
-	((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata, 8));
+      print_vms_time (byte_get ((unsigned char *) pnote->descdata, 8));
       printf ("\n");
       break;

@@ -20784,8 +20783,7 @@ print_ia64_vms_note (Elf_Internal_Note * pnote)
 	goto desc_size_fail;
       /* FIXME: Generate an error if descsz > 8 ?  */

-      print_vms_time
-	((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata, 8));
+      print_vms_time (byte_get ((unsigned char *) pnote->descdata, 8));
       printf ("\n");
       break;

@@ -20794,16 +20792,15 @@ print_ia64_vms_note (Elf_Internal_Note * pnote)
 	goto desc_size_fail;

       printf (_("   Major id: %u,  minor id: %u\n"),
-              (unsigned) byte_get ((unsigned char *)pnote->descdata, 4),
-              (unsigned) byte_get ((unsigned char *)pnote->descdata + 4, 4));
+	      (unsigned) byte_get ((unsigned char *) pnote->descdata, 4),
+	      (unsigned) byte_get ((unsigned char *) pnote->descdata + 4, 4));
       printf (_("   Last modified  : "));
-      print_vms_time
-        ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata + 8, 8));
+      print_vms_time (byte_get ((unsigned char *) pnote->descdata + 8, 8));
       printf (_("\n   Link flags  : "));
       printf ("0x%016" BFD_VMA_FMT "x\n",
-              (bfd_vma) byte_get ((unsigned char *)pnote->descdata + 16, 8));
+	      (bfd_vma) byte_get ((unsigned char *) pnote->descdata + 16, 8));
       printf (_("   Header flags: 0x%08x\n"),
-              (unsigned) byte_get ((unsigned char *)pnote->descdata + 24, 4));
+	      (unsigned) byte_get ((unsigned char *) pnote->descdata + 24, 4));
       printf (_("   Image id    : %.*s\n"), maxlen - 32, pnote->descdata + 32);
       break;
 #endif
diff --git a/gas/config/tc-arm.c b/gas/config/tc-arm.c
index 1721097cfca..2e6d175482e 100644
--- a/gas/config/tc-arm.c
+++ b/gas/config/tc-arm.c
@@ -3565,7 +3565,7 @@ add_to_lit_pool (unsigned int nbytes)
       imm1 = inst.operands[1].imm;
       imm2 = (inst.operands[1].regisimm ? inst.operands[1].reg
 	       : inst.relocs[0].exp.X_unsigned ? 0
-	       : ((bfd_int64_t) inst.operands[1].imm) >> 32);
+	       : (int64_t) inst.operands[1].imm >> 32);
       if (target_big_endian)
 	{
 	  imm1 = imm2;
@@ -8819,15 +8819,14 @@ neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
   return FAIL;
 }

-#if defined BFD_HOST_64_BIT
 /* Returns TRUE if double precision value V may be cast
    to single precision without loss of accuracy.  */

 static bool
-is_double_a_single (bfd_uint64_t v)
+is_double_a_single (uint64_t v)
 {
   int exp = (v >> 52) & 0x7FF;
-  bfd_uint64_t mantissa = v & 0xFFFFFFFFFFFFFULL;
+  uint64_t mantissa = v & 0xFFFFFFFFFFFFFULL;

   return ((exp == 0 || exp == 0x7FF
 	   || (exp >= 1023 - 126 && exp <= 1023 + 127))
@@ -8838,11 +8837,11 @@ is_double_a_single (bfd_uint64_t v)
    (ignoring the least significant bits in exponent and mantissa).  */

 static int
-double_to_single (bfd_uint64_t v)
+double_to_single (uint64_t v)
 {
   unsigned int sign = (v >> 63) & 1;
   int exp = (v >> 52) & 0x7FF;
-  bfd_uint64_t mantissa = v & 0xFFFFFFFFFFFFFULL;
+  uint64_t mantissa = v & 0xFFFFFFFFFFFFFULL;

   if (exp == 0x7FF)
     exp = 0xFF;
@@ -8865,7 +8864,6 @@ double_to_single (bfd_uint64_t v)
   mantissa >>= 29;
   return (sign << 31) | (exp << 23) | mantissa;
 }
-#endif /* BFD_HOST_64_BIT */

 enum lit_type
 {
@@ -8914,11 +8912,7 @@ move_or_literal_pool (int i, enum lit_type t, bool mode_3)
   if (inst.relocs[0].exp.X_op == O_constant
       || inst.relocs[0].exp.X_op == O_big)
     {
-#if defined BFD_HOST_64_BIT
-      bfd_uint64_t v;
-#else
-      valueT v;
-#endif
+      uint64_t v;
       if (inst.relocs[0].exp.X_op == O_big)
 	{
 	  LITTLENUM_TYPE w[X_PRECISION];
@@ -8933,7 +8927,6 @@ move_or_literal_pool (int i, enum lit_type t, bool mode_3)
 	  else
 	    l = generic_bignum;

-#if defined BFD_HOST_64_BIT
 	  v = l[3] & LITTLENUM_MASK;
 	  v <<= LITTLENUM_NUMBER_OF_BITS;
 	  v |= l[2] & LITTLENUM_MASK;
@@ -8941,11 +8934,6 @@ move_or_literal_pool (int i, enum lit_type t, bool mode_3)
 	  v |= l[1] & LITTLENUM_MASK;
 	  v <<= LITTLENUM_NUMBER_OF_BITS;
 	  v |= l[0] & LITTLENUM_MASK;
-#else
-	  v = l[1] & LITTLENUM_MASK;
-	  v <<= LITTLENUM_NUMBER_OF_BITS;
-	  v |= l[0] & LITTLENUM_MASK;
-#endif
 	}
       else
 	v = inst.relocs[0].exp.X_add_number;
@@ -9041,7 +9029,7 @@ move_or_literal_pool (int i, enum lit_type t, bool mode_3)
 		? inst.operands[1].reg
 		: inst.relocs[0].exp.X_unsigned
 		? 0
-		: ((bfd_int64_t)((int) immlo)) >> 32;
+		: (int64_t) (int) immlo >> 32;
 	      int cmode = neon_cmode_for_move_imm (immlo, immhi, false, &immbits,
 						   &op, 64, NT_invtype);

@@ -9090,7 +9078,6 @@ move_or_literal_pool (int i, enum lit_type t, bool mode_3)
 	     discrepancy between the output produced by an assembler built for
 	     a 32-bit-only host and the output produced from a 64-bit host, but
 	     this cannot be helped.  */
-#if defined BFD_HOST_64_BIT
 	  else if (!inst.operands[1].issingle
 		   && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
 	    {
@@ -9103,7 +9090,6 @@ move_or_literal_pool (int i, enum lit_type t, bool mode_3)
 		  return true;
 		}
 	    }
-#endif
 	}
     }

diff --git a/gas/config/tc-csky.c b/gas/config/tc-csky.c
index 2371eeb747e..5b824d89af0 100644
--- a/gas/config/tc-csky.c
+++ b/gas/config/tc-csky.c
@@ -215,7 +215,7 @@ enum
 unsigned int mach_flag = 0;
 unsigned int arch_flag = 0;
 unsigned int other_flag = 0;
-BFD_HOST_U_64_BIT isa_flag = 0;
+uint64_t isa_flag = 0;
 unsigned int dsp_flag = 0;

 typedef struct stack_size_entry
@@ -245,7 +245,7 @@ struct csky_macro_info
   const char *name;
   /* How many operands : if operands == 5, all of 1,2,3,4 are ok.  */
   long oprnd_num;
-  BFD_HOST_U_64_BIT isa_flag;
+  uint64_t isa_flag;
   /* Do the work.  */
   void (*handle_func)(void);
 };
@@ -591,14 +591,14 @@ struct csky_cpu_feature
 {
   const char unique;
   unsigned int arch_flag;
-  bfd_uint64_t isa_flag;
+  uint64_t isa_flag;
 };

 struct csky_cpu_version
 {
   int r;
   int p;
-  bfd_uint64_t isa_flag;
+  uint64_t isa_flag;
 };

 #define CSKY_FEATURE_MAX  10
@@ -608,7 +608,7 @@ struct csky_cpu_info
 {
   const char *name;
   unsigned int arch_flag;
-  bfd_uint64_t isa_flag;
+  uint64_t isa_flag;
   struct csky_cpu_feature features[CSKY_FEATURE_MAX];
   struct csky_cpu_version ver[CSKY_CPU_REVERISON_MAX];
 };
diff --git a/gas/config/tc-sparc.c b/gas/config/tc-sparc.c
index 222223f3549..4e443b1d28d 100644
--- a/gas/config/tc-sparc.c
+++ b/gas/config/tc-sparc.c
@@ -75,10 +75,10 @@ static enum { MM_TSO, MM_PSO, MM_RMO } sparc_memory_model = MM_RMO;
 #ifndef TE_SOLARIS
 /* Bitmask of instruction types seen so far, used to populate the
    GNU attributes section with hwcap information.  */
-static bfd_uint64_t hwcap_seen;
+static uint64_t hwcap_seen;
 #endif

-static bfd_uint64_t hwcap_allowed;
+static uint64_t hwcap_allowed;

 static int architecture_requested;
 static int warn_on_bump;
@@ -498,15 +498,15 @@ md_parse_option (int c, const char *arg)
 	    || opcode_arch > max_architecture)
 	  max_architecture = opcode_arch;

-        /* The allowed hardware capabilities are the implied by the
-           opcodes arch plus any extra capabilities defined in the GAS
-           arch.  */
-        hwcap_allowed
-          = (hwcap_allowed
-             | (((bfd_uint64_t) sparc_opcode_archs[opcode_arch].hwcaps2) << 32)
-             | (((bfd_uint64_t) sa->hwcap2_allowed) << 32)
-             | sparc_opcode_archs[opcode_arch].hwcaps
-             | sa->hwcap_allowed);
+	/* The allowed hardware capabilities are the implied by the
+	   opcodes arch plus any extra capabilities defined in the GAS
+	   arch.  */
+	hwcap_allowed
+	  = (hwcap_allowed
+	     | ((uint64_t) sparc_opcode_archs[opcode_arch].hwcaps2 << 32)
+	     | ((uint64_t) sa->hwcap2_allowed << 32)
+	     | sparc_opcode_archs[opcode_arch].hwcaps
+	     | sa->hwcap_allowed);
 	architecture_requested = 1;
       }
       break;
@@ -1607,7 +1607,7 @@ md_assemble (char *str)
 }

 static const char *
-get_hwcap_name (bfd_uint64_t mask)
+get_hwcap_name (uint64_t mask)
 {
   if (mask & HWCAP_MUL32)
     return "mul32";
@@ -3171,8 +3171,7 @@ sparc_ip (char *str, const struct sparc_opcode **pinsn)
               msg_str = sasi->name;
             }

-          bfd_uint64_t hwcaps
-	    = (((bfd_uint64_t) insn->hwcaps2) << 32) | insn->hwcaps;
+	  uint64_t hwcaps = ((uint64_t) insn->hwcaps2 << 32) | insn->hwcaps;

 #ifndef TE_SOLARIS
 	  if (hwcaps)
@@ -3211,10 +3210,10 @@ sparc_ip (char *str, const struct sparc_opcode **pinsn)
 		}
 	      current_architecture = needed_architecture;
 	      hwcap_allowed
-                = (hwcap_allowed
-                   | hwcaps
-                   | (((bfd_uint64_t) sparc_opcode_archs[current_architecture].hwcaps2) << 32)
-                   | sparc_opcode_archs[current_architecture].hwcaps);
+		= (hwcap_allowed
+		   | hwcaps
+		   | ((uint64_t) sparc_opcode_archs[current_architecture].hwcaps2 << 32)
+		   | sparc_opcode_archs[current_architecture].hwcaps);
 	    }
 	  /* Conflict.  */
 	  /* ??? This seems to be a bit fragile.  What if the next entry in
diff --git a/gas/config/tc-tilegx.c b/gas/config/tc-tilegx.c
index b627b7080e5..4fcc38c9034 100644
--- a/gas/config/tc-tilegx.c
+++ b/gas/config/tc-tilegx.c
@@ -789,16 +789,16 @@ emit_tilegx_instruction (tilegx_bundle_bits bits,
 static void
 check_illegal_reg_writes (void)
 {
-  BFD_HOST_U_64_BIT all_regs_written = 0;
+  uint64_t all_regs_written = 0;
   int j;

   for (j = 0; j < current_bundle_index; j++)
     {
       const struct tilegx_instruction *instr = &current_bundle[j];
       int k;
-      BFD_HOST_U_64_BIT regs =
-	((BFD_HOST_U_64_BIT)1) << instr->opcode->implicitly_written_register;
-      BFD_HOST_U_64_BIT conflict;
+      uint64_t regs =
+	(uint64_t) 1 << instr->opcode->implicitly_written_register;
+      uint64_t conflict;

       for (k = 0; k < instr->opcode->num_operands; k++)
 	{
@@ -808,12 +808,12 @@ check_illegal_reg_writes (void)
 	  if (operand->is_dest_reg)
 	    {
 	      int regno = instr->operand_values[k].X_add_number;
-	      BFD_HOST_U_64_BIT mask = ((BFD_HOST_U_64_BIT)1) << regno;
+	      uint64_t mask = (uint64_t) 1 << regno;

-	      if ((mask & (  (((BFD_HOST_U_64_BIT)1) << TREG_IDN1)
-			     | (((BFD_HOST_U_64_BIT)1) << TREG_UDN1)
-			     | (((BFD_HOST_U_64_BIT)1) << TREG_UDN2)
-			     | (((BFD_HOST_U_64_BIT)1) << TREG_UDN3))) != 0
+	      if ((mask & (  ((uint64_t) 1 << TREG_IDN1)
+			   | ((uint64_t) 1 << TREG_UDN1)
+			   | ((uint64_t) 1 << TREG_UDN2)
+			   | ((uint64_t) 1 << TREG_UDN3))) != 0
 		  && !allow_suspicious_bundles)
 		{
 		  as_bad (_("Writes to register '%s' are not allowed."),
@@ -825,7 +825,7 @@ check_illegal_reg_writes (void)
 	}

       /* Writing to the zero register doesn't count.  */
-      regs &= ~(((BFD_HOST_U_64_BIT)1) << TREG_ZERO);
+      regs &= ~((uint64_t) 1 << TREG_ZERO);

       conflict = all_regs_written & regs;
       if (conflict != 0 && !allow_suspicious_bundles)
diff --git a/gas/config/tc-tilepro.c b/gas/config/tc-tilepro.c
index af0be422f98..ca092d77a4b 100644
--- a/gas/config/tc-tilepro.c
+++ b/gas/config/tc-tilepro.c
@@ -677,16 +677,16 @@ emit_tilepro_instruction (tilepro_bundle_bits bits,
 static void
 check_illegal_reg_writes (void)
 {
-  BFD_HOST_U_64_BIT all_regs_written = 0;
+  uint64_t all_regs_written = 0;
   int j;

   for (j = 0; j < current_bundle_index; j++)
     {
       const struct tilepro_instruction *instr = &current_bundle[j];
       int k;
-      BFD_HOST_U_64_BIT regs =
-	((BFD_HOST_U_64_BIT)1) << instr->opcode->implicitly_written_register;
-      BFD_HOST_U_64_BIT conflict;
+      uint64_t regs =
+	(uint64_t) 1 << instr->opcode->implicitly_written_register;
+      uint64_t conflict;

       for (k = 0; k < instr->opcode->num_operands; k++)
 	{
@@ -696,12 +696,12 @@ check_illegal_reg_writes (void)
 	  if (operand->is_dest_reg)
 	    {
 	      int regno = instr->operand_values[k].X_add_number;
-	      BFD_HOST_U_64_BIT mask = ((BFD_HOST_U_64_BIT)1) << regno;
+	      uint64_t mask = (uint64_t) 1 << regno;

-	      if ((mask & (  (((BFD_HOST_U_64_BIT)1) << TREG_IDN1)
-			     | (((BFD_HOST_U_64_BIT)1) << TREG_UDN1)
-			     | (((BFD_HOST_U_64_BIT)1) << TREG_UDN2)
-			     | (((BFD_HOST_U_64_BIT)1) << TREG_UDN3))) != 0
+	      if ((mask & (  ((uint64_t) 1 << TREG_IDN1)
+			   | ((uint64_t) 1 << TREG_UDN1)
+			   | ((uint64_t) 1 << TREG_UDN2)
+			   | ((uint64_t) 1 << TREG_UDN3))) != 0
 		  && !allow_suspicious_bundles)
 		{
 		  as_bad (_("Writes to register '%s' are not allowed."),
@@ -713,7 +713,7 @@ check_illegal_reg_writes (void)
 	}

       /* Writing to the zero register doesn't count.  */
-      regs &= ~(((BFD_HOST_U_64_BIT)1) << TREG_ZERO);
+      regs &= ~((uint64_t) 1 << TREG_ZERO);

       conflict = all_regs_written & regs;
       if (conflict != 0 && !allow_suspicious_bundles)
diff --git a/gas/config/tc-z80.c b/gas/config/tc-z80.c
index 81fbfe3b0ae..714e704e24a 100644
--- a/gas/config/tc-z80.c
+++ b/gas/config/tc-z80.c
@@ -3910,11 +3910,11 @@ z80_tc_label_is_local (const char *name)
 #define EXP_MIN -0x10000
 #define EXP_MAX 0x10000
 static int
-str_to_broken_float (bool *signP, bfd_uint64_t *mantissaP, int *expP)
+str_to_broken_float (bool *signP, uint64_t *mantissaP, int *expP)
 {
   char *p;
   bool sign;
-  bfd_uint64_t mantissa = 0;
+  uint64_t mantissa = 0;
   int exponent = 0;
   int i;

@@ -4029,7 +4029,7 @@ str_to_broken_float (bool *signP, bfd_uint64_t *mantissaP, int *expP)
 static const char *
 str_to_zeda32(char *litP, int *sizeP)
 {
-  bfd_uint64_t mantissa;
+  uint64_t mantissa;
   bool sign;
   int exponent;
   unsigned i;
@@ -4088,7 +4088,7 @@ str_to_zeda32(char *litP, int *sizeP)
 static const char *
 str_to_float48(char *litP, int *sizeP)
 {
-  bfd_uint64_t mantissa;
+  uint64_t mantissa;
   bool sign;
   int exponent;
   unsigned i;
diff --git a/gas/config/te-vms.c b/gas/config/te-vms.c
index 015c95867f0..6661a3b6a72 100644
--- a/gas/config/te-vms.c
+++ b/gas/config/te-vms.c
@@ -339,7 +339,7 @@ vms_file_stats_name (const char *dirname,
   return 0;
 }

-bfd_uint64_t
+uint64_t
 vms_dwarf2_file_time_name (const char *filename, const char *dirname)
 {
   long long cdt;
diff --git a/gas/config/te-vms.h b/gas/config/te-vms.h
index ffe7f5e8f37..08f218502de 100644
--- a/gas/config/te-vms.h
+++ b/gas/config/te-vms.h
@@ -20,7 +20,7 @@
 #define TE_VMS
 #include "obj-format.h"

-extern bfd_uint64_t vms_dwarf2_file_time_name (const char *, const char *);
+extern uint64_t vms_dwarf2_file_time_name (const char *, const char *);
 extern long vms_dwarf2_file_size_name (const char *, const char *);
 extern char *vms_dwarf2_file_name (const char *, const char *);

diff --git a/gdb/findcmd.c b/gdb/findcmd.c
index ff13f22e970..ed2cea7b74d 100644
--- a/gdb/findcmd.c
+++ b/gdb/findcmd.c
@@ -30,7 +30,7 @@
 /* Copied from bfd_put_bits.  */

 static void
-put_bits (bfd_uint64_t data, gdb::byte_vector &buf, int bits, bfd_boolean big_p)
+put_bits (uint64_t data, gdb::byte_vector &buf, int bits, bfd_boolean big_p)
 {
   int i;
   int bytes;
diff --git a/gdb/tilegx-tdep.c b/gdb/tilegx-tdep.c
index 7930db72779..9668aa80b53 100644
--- a/gdb/tilegx-tdep.c
+++ b/gdb/tilegx-tdep.c
@@ -375,7 +375,7 @@ tilegx_analyze_prologue (struct gdbarch* gdbarch,
   CORE_ADDR instbuf_start;
   unsigned int instbuf_size;
   int status;
-  bfd_uint64_t bundle;
+  uint64_t bundle;
   struct tilegx_decoded_instruction
     decoded[TILEGX_MAX_INSTRUCTIONS_PER_BUNDLE];
   int num_insns;
diff --git a/gprof/gmon_io.c b/gprof/gmon_io.c
index c613809d396..2b4dd26375b 100644
--- a/gprof/gmon_io.c
+++ b/gprof/gmon_io.c
@@ -48,10 +48,8 @@ enum gmon_ptr_signedness {
 static enum gmon_ptr_size gmon_get_ptr_size (void);
 static enum gmon_ptr_signedness gmon_get_ptr_signedness (void);

-#ifdef BFD_HOST_U_64_BIT
-static int gmon_io_read_64 (FILE *, BFD_HOST_U_64_BIT *);
-static int gmon_io_write_64 (FILE *, BFD_HOST_U_64_BIT);
-#endif
+static int gmon_io_read_64 (FILE *, uint64_t *);
+static int gmon_io_write_64 (FILE *, uint64_t);
 static int gmon_read_raw_arc
   (FILE *, bfd_vma *, bfd_vma *, unsigned long *);
 static int gmon_write_raw_arc
@@ -109,9 +107,8 @@ gmon_io_read_32 (FILE *ifp, unsigned int *valp)
   return 0;
 }

-#ifdef BFD_HOST_U_64_BIT
 static int
-gmon_io_read_64 (FILE *ifp, BFD_HOST_U_64_BIT *valp)
+gmon_io_read_64 (FILE *ifp, uint64_t *valp)
 {
   char buf[8];

@@ -120,15 +117,12 @@ gmon_io_read_64 (FILE *ifp, BFD_HOST_U_64_BIT *valp)
   *valp = bfd_get_64 (core_bfd, buf);
   return 0;
 }
-#endif

 int
 gmon_io_read_vma (FILE *ifp, bfd_vma *valp)
 {
   unsigned int val32;
-#ifdef BFD_HOST_U_64_BIT
-  BFD_HOST_U_64_BIT val64;
-#endif
+  uint64_t val64;

   switch (gmon_get_ptr_size ())
     {
@@ -136,23 +130,19 @@ gmon_io_read_vma (FILE *ifp, bfd_vma *valp)
       if (gmon_io_read_32 (ifp, &val32))
 	return 1;
       if (gmon_get_ptr_signedness () == ptr_signed)
-        *valp = (int) val32;
+	*valp = (int) val32;
       else
-        *valp = val32;
+	*valp = val32;
       break;

-#ifdef BFD_HOST_U_64_BIT
     case ptr_64bit:
       if (gmon_io_read_64 (ifp, &val64))
 	return 1;
-#ifdef BFD_HOST_64_BIT
       if (gmon_get_ptr_signedness () == ptr_signed)
-        *valp = (BFD_HOST_64_BIT) val64;
+	*valp = (int64_t) val64;
       else
-#endif
-        *valp = val64;
+	*valp = val64;
       break;
-#endif
     }
   return 0;
 }
@@ -176,9 +166,8 @@ gmon_io_write_32 (FILE *ofp, unsigned int val)
   return 0;
 }

-#ifdef BFD_HOST_U_64_BIT
 static int
-gmon_io_write_64 (FILE *ofp, BFD_HOST_U_64_BIT val)
+gmon_io_write_64 (FILE *ofp, uint64_t val)
 {
   char buf[8];

@@ -187,7 +176,6 @@ gmon_io_write_64 (FILE *ofp, BFD_HOST_U_64_BIT val)
     return 1;
   return 0;
 }
-#endif

 int
 gmon_io_write_vma (FILE *ofp, bfd_vma val)
@@ -200,12 +188,10 @@ gmon_io_write_vma (FILE *ofp, bfd_vma val)
 	return 1;
       break;

-#ifdef BFD_HOST_U_64_BIT
     case ptr_64bit:
-      if (gmon_io_write_64 (ofp, (BFD_HOST_U_64_BIT) val))
+      if (gmon_io_write_64 (ofp, (uint64_t) val))
 	return 1;
       break;
-#endif
     }
   return 0;
 }
@@ -232,9 +218,7 @@ gmon_io_write (FILE *ofp, char *buf, size_t n)
 static int
 gmon_read_raw_arc (FILE *ifp, bfd_vma *fpc, bfd_vma *spc, unsigned long *cnt)
 {
-#ifdef BFD_HOST_U_64_BIT
-  BFD_HOST_U_64_BIT cnt64;
-#endif
+  uint64_t cnt64;
   unsigned int cnt32;

   if (gmon_io_read_vma (ifp, fpc)
@@ -249,13 +233,11 @@ gmon_read_raw_arc (FILE *ifp, bfd_vma *fpc, bfd_vma *spc, unsigned long *cnt)
       *cnt = cnt32;
       break;

-#ifdef BFD_HOST_U_64_BIT
     case ptr_64bit:
       if (gmon_io_read_64 (ifp, &cnt64))
 	return 1;
       *cnt = cnt64;
       break;
-#endif

     default:
       return 1;
@@ -278,12 +260,10 @@ gmon_write_raw_arc (FILE *ofp, bfd_vma fpc, bfd_vma spc, unsigned long cnt)
 	return 1;
       break;

-#ifdef BFD_HOST_U_64_BIT
     case ptr_64bit:
-      if (gmon_io_write_64 (ofp, (BFD_HOST_U_64_BIT) cnt))
+      if (gmon_io_write_64 (ofp, (uint64_t) cnt))
 	return 1;
       break;
-#endif
     }
   return 0;
 }
diff --git a/include/elf/nfp.h b/include/elf/nfp.h
index 5a06051196c..c89cefff27b 100644
--- a/include/elf/nfp.h
+++ b/include/elf/nfp.h
@@ -102,7 +102,7 @@ extern "C"
 #define SHF_NFP_INIT		0x80000000
 #define SHF_NFP_INIT2		0x40000000
 #define SHF_NFP_SCS(shf)	(((shf) >> 32) & 0xFF)
-#define SHF_NFP_SET_SCS(v)	(((BFD_HOST_U_64_BIT)((v) & 0xFF)) << 32)
+#define SHF_NFP_SET_SCS(v)	((uint64_t) ((v) & 0xFF) << 32)

 /* NFP Section Info
    For PROGBITS and NOBITS sections:
diff --git a/include/opcode/csky.h b/include/opcode/csky.h
index ed00bfd7cd6..faecba11611 100644
--- a/include/opcode/csky.h
+++ b/include/opcode/csky.h
@@ -22,46 +22,46 @@
 #include "dis-asm.h"

 /* The following bitmasks control instruction set architecture.  */
-#define CSKYV1_ISA_E1       ((bfd_uint64_t)1 << 0)
-#define CSKYV2_ISA_E1       ((bfd_uint64_t)1 << 1)
-#define CSKYV2_ISA_1E2      ((bfd_uint64_t)1 << 2)
-#define CSKYV2_ISA_2E3      ((bfd_uint64_t)1 << 3)
-#define CSKYV2_ISA_3E7      ((bfd_uint64_t)1 << 4)
-#define CSKYV2_ISA_7E10     ((bfd_uint64_t)1 << 5)
-#define CSKYV2_ISA_3E3R1    ((bfd_uint64_t)1 << 6)
-#define CSKYV2_ISA_3E3R2    ((bfd_uint64_t)1 << 7)
-#define CSKYV2_ISA_10E60    ((bfd_uint64_t)1 << 8)
-#define CSKYV2_ISA_3E3R3    ((bfd_uint64_t)1 << 9)
-
-#define CSKY_ISA_TRUST      ((bfd_uint64_t)1 << 11)
-#define CSKY_ISA_CACHE      ((bfd_uint64_t)1 << 12)
-#define CSKY_ISA_NVIC       ((bfd_uint64_t)1 << 13)
-#define CSKY_ISA_CP         ((bfd_uint64_t)1 << 14)
-#define CSKY_ISA_MP         ((bfd_uint64_t)1 << 15)
-#define CSKY_ISA_MP_1E2     ((bfd_uint64_t)1 << 16)
-#define CSKY_ISA_JAVA       ((bfd_uint64_t)1 << 17)
-#define CSKY_ISA_MAC        ((bfd_uint64_t)1 << 18)
-#define CSKY_ISA_MAC_DSP    ((bfd_uint64_t)1 << 19)
+#define CSKYV1_ISA_E1       ((uint64_t) 1 << 0)
+#define CSKYV2_ISA_E1       ((uint64_t) 1 << 1)
+#define CSKYV2_ISA_1E2      ((uint64_t) 1 << 2)
+#define CSKYV2_ISA_2E3      ((uint64_t) 1 << 3)
+#define CSKYV2_ISA_3E7      ((uint64_t) 1 << 4)
+#define CSKYV2_ISA_7E10     ((uint64_t) 1 << 5)
+#define CSKYV2_ISA_3E3R1    ((uint64_t) 1 << 6)
+#define CSKYV2_ISA_3E3R2    ((uint64_t) 1 << 7)
+#define CSKYV2_ISA_10E60    ((uint64_t) 1 << 8)
+#define CSKYV2_ISA_3E3R3    ((uint64_t) 1 << 9)
+
+#define CSKY_ISA_TRUST      ((uint64_t) 1 << 11)
+#define CSKY_ISA_CACHE      ((uint64_t) 1 << 12)
+#define CSKY_ISA_NVIC       ((uint64_t) 1 << 13)
+#define CSKY_ISA_CP         ((uint64_t) 1 << 14)
+#define CSKY_ISA_MP         ((uint64_t) 1 << 15)
+#define CSKY_ISA_MP_1E2     ((uint64_t) 1 << 16)
+#define CSKY_ISA_JAVA       ((uint64_t) 1 << 17)
+#define CSKY_ISA_MAC        ((uint64_t) 1 << 18)
+#define CSKY_ISA_MAC_DSP    ((uint64_t) 1 << 19)

 /* Base ISA for csky v1 and v2.  */
-#define CSKY_ISA_DSP        ((bfd_uint64_t)1 << 20)
-#define CSKY_ISA_DSP_1E2    ((bfd_uint64_t)1 << 21)
-#define CSKY_ISA_DSP_ENHANCE ((bfd_uint64_t)1 << 22)
-#define CSKY_ISA_DSPE60     ((bfd_uint64_t)1 << 23)
+#define CSKY_ISA_DSP        ((uint64_t) 1 << 20)
+#define CSKY_ISA_DSP_1E2    ((uint64_t) 1 << 21)
+#define CSKY_ISA_DSP_ENHANCE ((uint64_t) 1 << 22)
+#define CSKY_ISA_DSPE60     ((uint64_t) 1 << 23)

 /* Base float instruction (803f & 810f).  */
-#define CSKY_ISA_FLOAT_E1   ((bfd_uint64_t)1 << 25)
+#define CSKY_ISA_FLOAT_E1   ((uint64_t) 1 << 25)
 /* M_FLOAT support (810f).  */
-#define CSKY_ISA_FLOAT_1E2  ((bfd_uint64_t)1 << 26)
+#define CSKY_ISA_FLOAT_1E2  ((uint64_t) 1 << 26)
 /* 803 support (803f).  */
-#define CSKY_ISA_FLOAT_1E3  ((bfd_uint64_t)1 << 27)
+#define CSKY_ISA_FLOAT_1E3  ((uint64_t) 1 << 27)
 /* 807 support (803f & 807f).  */
-#define CSKY_ISA_FLOAT_3E4  ((bfd_uint64_t)1 << 28)
+#define CSKY_ISA_FLOAT_3E4  ((uint64_t) 1 << 28)
 /* 860 support.  */
-#define CSKY_ISA_FLOAT_7E60 ((bfd_uint64_t)1 << 36)
+#define CSKY_ISA_FLOAT_7E60 ((uint64_t) 1 << 36)
 /* Vector DSP support.  */
-#define CSKY_ISA_VDSP       ((bfd_uint64_t)1 << 29)
-#define CSKY_ISA_VDSP_2     ((bfd_uint64_t)1 << 30)
+#define CSKY_ISA_VDSP       ((uint64_t) 1 << 29)
+#define CSKY_ISA_VDSP_2     ((uint64_t) 1 << 30)

 /* The following bitmasks control cpu architecture for CSKY.  */
 #define CSKY_ABI_V1         (1 << 28)
diff --git a/include/opcode/ia64.h b/include/opcode/ia64.h
index fbdd8f14e65..42a6812c3f8 100644
--- a/include/opcode/ia64.h
+++ b/include/opcode/ia64.h
@@ -29,7 +29,7 @@
 extern "C" {
 #endif

-typedef BFD_HOST_U_64_BIT ia64_insn;
+typedef uint64_t ia64_insn;

 enum ia64_insn_type
   {
diff --git a/opcodes/csky-dis.c b/opcodes/csky-dis.c
index b7c833623e5..99103ff57b5 100644
--- a/opcodes/csky-dis.c
+++ b/opcodes/csky-dis.c
@@ -49,7 +49,7 @@ struct csky_dis_info
   disassemble_info *info;
   /* Opcode information.  */
   struct csky_opcode_info const *opinfo;
-  BFD_HOST_U_64_BIT isa;
+  uint64_t isa;
   /* The value of operand to show.  */
   int value;
   /* Whether to look up/print a symbol name.  */
diff --git a/opcodes/csky-opc.h b/opcodes/csky-opc.h
index b65efe19d9f..d2db90ede95 100644
--- a/opcodes/csky-opc.h
+++ b/opcodes/csky-opc.h
@@ -271,8 +271,8 @@ struct csky_opcode
   /* Encodings for 32-bit opcodes.  */
   struct csky_opcode_info op32[OP_TABLE_NUM];
   /* Instruction set flag.  */
-  BFD_HOST_U_64_BIT isa_flag16;
-  BFD_HOST_U_64_BIT isa_flag32;
+  uint64_t isa_flag16;
+  uint64_t isa_flag32;
   /* Whether this insn needs relocation, 0: no, !=0: yes.  */
   signed int reloc16;
   signed int reloc32;
diff --git a/opcodes/ia64-dis.c b/opcodes/ia64-dis.c
index 5eb37277a5d..e76f40393c6 100644
--- a/opcodes/ia64-dis.c
+++ b/opcodes/ia64-dis.c
@@ -73,7 +73,7 @@ print_insn_ia64 (bfd_vma memaddr, struct disassemble_info *info)
   const struct ia64_operand *odesc;
   const struct ia64_opcode *idesc;
   const char *err, *str, *tname;
-  BFD_HOST_U_64_BIT value;
+  uint64_t value;
   bfd_byte bundle[16];
   enum ia64_unit unit;
   char regname[16];
--
2.31.1

