[RFC] bfd: use bfd_vma for the 64-bit version of put[lb] and get[lb]

Message ID 5f482299-6c60-b2b3-9abe-f4a55a5a26c5@univ-grenoble-alpes.fr
State New, archived
Headers
Series [RFC] bfd: use bfd_vma for the 64-bit version of put[lb] and get[lb] |

Commit Message

Frédéric Pétrot Oct. 4, 2022, 8:03 p.m. UTC
  Hi,

During summer (around Aug.4) Alan replaced in many places the use
of bfd_vma and such by the c99 types.
However,  when compiling for  an ad-hoc target of ours,  the fact
that the 64-bit version  of  the  put  and get functions does not
share the same prototypes as the other bit-width versions needs a
patch while making the prototypes consistent might be acceptable,
what do you think?

Thanks,
Frédéric


The 16-bit, 24-bit and 32-bit versions of these functions use an
argument of type  bfd_[signed_]vma while the 64-bit version uses
[u]int64_t.  Given the comment in front of the definition of the
bfd vma  types in  bfd-in.h, the  use of  the bfd specific types
should be possible and would make the code consistent across all
function versions.

bfd/
    * bfd-in.h: change argument or  return value types in put/get
                functions prototypes
    * libbfd.c: likewise for implementations


---
  bfd/bfd-in.h | 12 ++++++------
  bfd/libbfd.c | 12 ++++++------
  2 files changed, 12 insertions(+), 12 deletions(-)
  

Comments

Alan Modra Oct. 5, 2022, 2:59 a.m. UTC | #1
> -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_getb64 (const void *);
> +bfd_vma bfd_getl64 (const void *);
> +bfd_signed_vma bfd_getb_signed_64 (const void *);
> +bfd_signed_vma bfd_getl_signed_64 (const void *);

No, you can't use bfd_vma here.  Configuring on a 32-bit host without
--enable-64-bit-bfd or selecting a 64-bit target will result in
bfd_vma being a 32-bit type.
  

Patch

diff --git a/bfd/bfd-in.h b/bfd/bfd-in.h
index 4765ea80536..9efb5ce5a84 100644
--- a/bfd/bfd-in.h
+++ b/bfd/bfd-in.h
@@ -403,10 +403,10 @@  extern bool bfd_record_phdr

  /* Byte swapping routines.  */

-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_getb64 (const void *);
+bfd_vma bfd_getl64 (const void *);
+bfd_signed_vma bfd_getb_signed_64 (const void *);
+bfd_signed_vma 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 *);
@@ -415,8 +415,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 (uint64_t, void *);
-void bfd_putl64 (uint64_t, void *);
+void bfd_putb64 (bfd_vma, void *);
+void bfd_putl64 (bfd_vma, void *);
  void bfd_putb32 (bfd_vma, void *);
  void bfd_putl32 (bfd_vma, void *);
  void bfd_putb24 (bfd_vma, void *);
diff --git a/bfd/libbfd.c b/bfd/libbfd.c
index d33f3416206..5eab59d2e76 100644
--- a/bfd/libbfd.c
+++ b/bfd/libbfd.c
@@ -757,7 +757,7 @@  bfd_getl_signed_32 (const void *p)
    return COERCE32 (v);
  }

-uint64_t
+bfd_vma
  bfd_getb64 (const void *p)
  {
    const bfd_byte *addr = (const bfd_byte *) p;
@@ -775,7 +775,7 @@  bfd_getb64 (const void *p)
    return v;
  }

-uint64_t
+bfd_vma
  bfd_getl64 (const void *p)
  {
    const bfd_byte *addr = (const bfd_byte *) p;
@@ -793,7 +793,7 @@  bfd_getl64 (const void *p)
    return v;
  }

-int64_t
+bfd_signed_vma
  bfd_getb_signed_64 (const void *p)
  {
    const bfd_byte *addr = (const bfd_byte *) p;
@@ -811,7 +811,7 @@  bfd_getb_signed_64 (const void *p)
    return COERCE64 (v);
  }

-int64_t
+bfd_signed_vma
  bfd_getl_signed_64 (const void *p)
  {
    const bfd_byte *addr = (const bfd_byte *) p;
@@ -850,7 +850,7 @@  bfd_putl32 (bfd_vma data, void *p)
  }

  void
-bfd_putb64 (uint64_t data, void *p)
+bfd_putb64 (bfd_vma data, void *p)
  {
    bfd_byte *addr = (bfd_byte *) p;
    addr[0] = (data >> (7*8)) & 0xff;
@@ -864,7 +864,7 @@  bfd_putb64 (uint64_t data, void *p)
  }

  void
-bfd_putl64 (uint64_t data, void *p)
+bfd_putl64 (bfd_vma data, void *p)
  {
    bfd_byte *addr = (bfd_byte *) p;
    addr[7] = (data >> (7*8)) & 0xff;