public inbox for binutils-cvs@sourceware.org
help / color / mirror / Atom feed
From: Alan Modra <amodra@sourceware.org>
To: bfd-cvs@sourceware.org
Subject: [binutils-gdb/binutils-2_39-branch] PR29348, BFD_VMA_FMT wrong
Date: Mon,  1 Aug 2022 01:08:50 +0000 (GMT)	[thread overview]
Message-ID: <20220801010850.55A253858412@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=b336123a087f9a85e7b24d7e420bd44b9c9d3552

commit b336123a087f9a85e7b24d7e420bd44b9c9d3552
Author: Alan Modra <amodra@gmail.com>
Date:   Sun Jul 31 19:25:32 2022 +0930

    PR29348, BFD_VMA_FMT wrong
    
    There is a problem with my commit 0e3c1eebb2, which replaced
    bfd_uint64_t with uint64_t: Some hosts typedef int64_t to long long
    even when long is the same size as long long.  That confuses the code
    choosing one of "l", "ll", or "I64" for BFD_VMA_FMT, and results in
    warnings.
    
    Write a direct configure test for the printf int64_t style instead.
    This removes the last use of BFD_HOST_64BIT_LONG, so delete that.
    Note that the changes to configure.com are pure guesswork.
    
            PR 29348
            * bfd-in.h (BFD_HOST_64BIT_LONG): Don't define.
            (BFD_VMA_FMT): Define using BFD_INT64_FMT when 64-bit.
            (bfd_vma, bfd_signed_vma): Move comments to 64-bit typedefs.
            * configure.ac (BFD_HOST_64BIT_LONG): Delete.
            (BFD_INT64_FMT): New config test.
            * configure.com: Update similarly.
            * Makefile.in: Regenerate.
            * bfd-in2.h: Regenerate.
            * configure: Regenerate.
    
    (cherry picked from commit 1a5178fe284547ef2abd8ae66588c9999d61c524)

Diff:
---
 bfd/Makefile.in   |  2 +-
 bfd/bfd-in.h      | 34 ++++++++++++----------------------
 bfd/bfd-in2.h     | 34 ++++++++++++----------------------
 bfd/configure     | 42 ++++++++++++++++++++++++++++++++++--------
 bfd/configure.ac  | 19 ++++++++++++-------
 bfd/configure.com | 30 +++++++++++++++++++++++++++---
 6 files changed, 98 insertions(+), 63 deletions(-)

diff --git a/bfd/Makefile.in b/bfd/Makefile.in
index d3ef4c2524b..a26f74d7199 100644
--- a/bfd/Makefile.in
+++ b/bfd/Makefile.in
@@ -330,7 +330,7 @@ AUTOCONF = @AUTOCONF@
 AUTOHEADER = @AUTOHEADER@
 AUTOMAKE = @AUTOMAKE@
 AWK = @AWK@
-BFD_HOST_64BIT_LONG = @BFD_HOST_64BIT_LONG@
+BFD_INT64_FMT = @BFD_INT64_FMT@
 CATALOGS = @CATALOGS@
 CATOBJEXT = @CATOBJEXT@
 CC = @CC@
diff --git a/bfd/bfd-in.h b/bfd/bfd-in.h
index dce682af997..9d0738a232a 100644
--- a/bfd/bfd-in.h
+++ b/bfd/bfd-in.h
@@ -69,8 +69,6 @@ extern "C" {
 /* The word size of the default bfd target.  */
 #define BFD_DEFAULT_TARGET_SIZE @bfd_default_target_size@
 
-#define BFD_HOST_64BIT_LONG @BFD_HOST_64BIT_LONG@
-
 #include <inttypes.h>
 
 #if BFD_ARCH_SIZE >= 64
@@ -101,42 +99,34 @@ typedef struct bfd bfd;
 
 #ifdef BFD64
 
+/* Represent a target address.  Also used as a generic unsigned type
+   which is guaranteed to be big enough to hold any arithmetic types
+   we need to deal with.  */
 typedef uint64_t bfd_vma;
+
+/* A generic signed type which is guaranteed to be big enough to hold any
+   arithmetic types we need to deal with.  Can be assumed to be compatible
+   with bfd_vma in the same way that signed and unsigned ints are compatible
+   (as parameters, in assignment, etc).  */
 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"
-#elif defined (__MSVCRT__)
-#define BFD_VMA_FMT "I64"
-#else
-#define BFD_VMA_FMT "ll"
-#endif
+#define BFD_VMA_FMT @BFD_INT64_FMT@
 
-#ifndef fprintf_vma
-#define sprintf_vma(s,x) sprintf (s, "%016" BFD_VMA_FMT "x", x)
 #define fprintf_vma(f,x) fprintf (f, "%016" BFD_VMA_FMT "x", x)
-#endif
+#define sprintf_vma(s,x) sprintf (s, "%016" BFD_VMA_FMT "x", x)
 
 #else /* not BFD64  */
 
-/* Represent a target address.  Also used as a generic unsigned type
-   which is guaranteed to be big enough to hold any arithmetic types
-   we need to deal with.  */
 typedef unsigned long bfd_vma;
-
-/* A generic signed type which is guaranteed to be big enough to hold any
-   arithmetic types we need to deal with.  Can be assumed to be compatible
-   with bfd_vma in the same way that signed and unsigned ints are compatible
-   (as parameters, in assignment, etc).  */
 typedef long bfd_signed_vma;
-
 typedef unsigned long symvalue;
 typedef unsigned long bfd_size_type;
 
-/* Print a bfd_vma x on stream s.  */
 #define BFD_VMA_FMT "l"
+
 #define fprintf_vma(s,x) fprintf (s, "%08" BFD_VMA_FMT "x", x)
 #define sprintf_vma(s,x) sprintf (s, "%08" BFD_VMA_FMT "x", x)
 
diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index 4e1182e93d4..1f0f18a7e75 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -76,8 +76,6 @@ extern "C" {
 /* The word size of the default bfd target.  */
 #define BFD_DEFAULT_TARGET_SIZE @bfd_default_target_size@
 
-#define BFD_HOST_64BIT_LONG @BFD_HOST_64BIT_LONG@
-
 #include <inttypes.h>
 
 #if BFD_ARCH_SIZE >= 64
@@ -108,42 +106,34 @@ typedef struct bfd bfd;
 
 #ifdef BFD64
 
+/* Represent a target address.  Also used as a generic unsigned type
+   which is guaranteed to be big enough to hold any arithmetic types
+   we need to deal with.  */
 typedef uint64_t bfd_vma;
+
+/* A generic signed type which is guaranteed to be big enough to hold any
+   arithmetic types we need to deal with.  Can be assumed to be compatible
+   with bfd_vma in the same way that signed and unsigned ints are compatible
+   (as parameters, in assignment, etc).  */
 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"
-#elif defined (__MSVCRT__)
-#define BFD_VMA_FMT "I64"
-#else
-#define BFD_VMA_FMT "ll"
-#endif
+#define BFD_VMA_FMT @BFD_INT64_FMT@
 
-#ifndef fprintf_vma
-#define sprintf_vma(s,x) sprintf (s, "%016" BFD_VMA_FMT "x", x)
 #define fprintf_vma(f,x) fprintf (f, "%016" BFD_VMA_FMT "x", x)
-#endif
+#define sprintf_vma(s,x) sprintf (s, "%016" BFD_VMA_FMT "x", x)
 
 #else /* not BFD64  */
 
-/* Represent a target address.  Also used as a generic unsigned type
-   which is guaranteed to be big enough to hold any arithmetic types
-   we need to deal with.  */
 typedef unsigned long bfd_vma;
-
-/* A generic signed type which is guaranteed to be big enough to hold any
-   arithmetic types we need to deal with.  Can be assumed to be compatible
-   with bfd_vma in the same way that signed and unsigned ints are compatible
-   (as parameters, in assignment, etc).  */
 typedef long bfd_signed_vma;
-
 typedef unsigned long symvalue;
 typedef unsigned long bfd_size_type;
 
-/* Print a bfd_vma x on stream s.  */
 #define BFD_VMA_FMT "l"
+
 #define fprintf_vma(s,x) fprintf (s, "%08" BFD_VMA_FMT "x", x)
 #define sprintf_vma(s,x) sprintf (s, "%08" BFD_VMA_FMT "x", x)
 
diff --git a/bfd/configure b/bfd/configure
index 9ace0bc3fb4..b9b9c74d650 100755
--- a/bfd/configure
+++ b/bfd/configure
@@ -652,11 +652,11 @@ TDEFINES
 SHARED_LIBADD
 SHARED_LDFLAGS
 LIBM
+BFD_INT64_FMT
 zlibinc
 zlibdir
 EXEEXT_FOR_BUILD
 CC_FOR_BUILD
-BFD_HOST_64BIT_LONG
 HDEFINES
 MSGMERGE
 MSGFMT
@@ -12841,13 +12841,6 @@ if test "x${ac_cv_sizeof_void_p}" = "x8"; then
   host64=true
 fi
 
-BFD_HOST_64BIT_LONG=0
-if test "x${ac_cv_sizeof_long}" = "x8"; then
-  BFD_HOST_64BIT_LONG=1
-fi
-
-
-
 # Put a plausible default for CC_FOR_BUILD in Makefile.
 if test -z "$CC_FOR_BUILD"; then
   if test "x$cross_compiling" = "xno"; then
@@ -13041,6 +13034,39 @@ $as_echo "#define HAVE_HIDDEN 1" >>confdefs.h
 
 fi
 
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking printf int64_t format" >&5
+$as_echo_n "checking printf int64_t format... " >&6; }
+if ${bfd_cv_int64_fmt+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  for style in I64 ll l; do
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+       #define __STDC_FORMAT_MACROS 1
+       #include <stdio.h>
+       #include <inttypes.h>
+       extern char PRId64_probe[sizeof PRId64 == sizeof "${style}d" ? 1 : -1];
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  bfd_cv_int64_fmt=${style}
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+  done
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $bfd_cv_int64_fmt" >&5
+$as_echo "$bfd_cv_int64_fmt" >&6; }
+BFD_INT64_FMT=\"$bfd_cv_int64_fmt\"
+
+
 # Check if linker supports --as-needed and --no-as-needed options
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking linker --as-needed support" >&5
 $as_echo_n "checking linker --as-needed support... " >&6; }
diff --git a/bfd/configure.ac b/bfd/configure.ac
index aad4f3c83a5..6146efb5ae3 100644
--- a/bfd/configure.ac
+++ b/bfd/configure.ac
@@ -218,13 +218,6 @@ if test "x${ac_cv_sizeof_void_p}" = "x8"; then
   host64=true
 fi
 
-BFD_HOST_64BIT_LONG=0
-if test "x${ac_cv_sizeof_long}" = "x8"; then
-  BFD_HOST_64BIT_LONG=1
-fi
-
-AC_SUBST(BFD_HOST_64BIT_LONG)
-
 BFD_CC_FOR_BUILD
 
 AC_CHECK_HEADERS(fcntl.h sys/file.h sys/resource.h sys/stat.h sys/types.h \
@@ -255,6 +248,18 @@ if test $bfd_cv_hidden = yes; then
 	    [Define if your compiler supports hidden visibility.])
 fi
 
+AC_CACHE_CHECK([printf int64_t format], [bfd_cv_int64_fmt],
+  for style in I64 ll l; do
+    [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+       #define __STDC_FORMAT_MACROS 1
+       #include <stdio.h>
+       #include <inttypes.h>
+       extern char PRId64_probe[sizeof PRId64 == sizeof "${style}d" ? 1 : -1];
+      ]])], [bfd_cv_int64_fmt=${style}], [])]
+  done)
+BFD_INT64_FMT=\"$bfd_cv_int64_fmt\"
+AC_SUBST(BFD_INT64_FMT)
+
 # Check if linker supports --as-needed and --no-as-needed options
 AC_CACHE_CHECK(linker --as-needed support, bfd_cv_ld_as_needed,
 	[bfd_cv_ld_as_needed=no
diff --git a/bfd/configure.com b/bfd/configure.com
index cc8499a4589..cfff494a561 100644
--- a/bfd/configure.com
+++ b/bfd/configure.com
@@ -60,11 +60,11 @@ $DECK
       ERASE(match_pos);
       COPY_TEXT('64');
    ENDIF;
-   match_pos := SEARCH_QUIETLY('@BFD_HOST_64BIT_LONG@', FORWARD, EXACT, rang);
+   match_pos := SEARCH_QUIETLY('@BFD_INT64_FMT@', FORWARD, EXACT, rang);
    IF match_pos <> 0 THEN;
       POSITION(BEGINNING_OF(match_pos));
       ERASE(match_pos);
-      COPY_TEXT('0');
+      COPY_TEXT('"l"');
    ENDIF;
    match_pos := SEARCH_QUIETLY('@bfd_file_ptr@', FORWARD, EXACT, rang);
    IF match_pos <> 0 THEN;
@@ -114,7 +114,31 @@ $DECK
       ERASE(match_pos);
       COPY_TEXT('32');
    ENDIF;
-   match_pos := SEARCH_QUIETLY('@BFD_HOST_64BIT_LONG@', FORWARD, EXACT, rang);
+   match_pos := SEARCH_QUIETLY('@bfd_default_target_size@', FORWARD, EXACT, rang);
+   IF match_pos <> 0 THEN;
+      POSITION(BEGINNING_OF(match_pos));
+      ERASE(match_pos);
+      COPY_TEXT('32');
+   ENDIF;
+   match_pos := SEARCH_QUIETLY('@BFD_INT64_FMT@', FORWARD, EXACT, rang);
+   IF match_pos <> 0 THEN;
+      POSITION(BEGINNING_OF(match_pos));
+      ERASE(match_pos);
+      COPY_TEXT('"ll"');
+   ENDIF;
+   match_pos := SEARCH_QUIETLY('@bfd_file_ptr@', FORWARD, EXACT, rang);
+   IF match_pos <> 0 THEN;
+      POSITION(BEGINNING_OF(match_pos));
+      ERASE(match_pos);
+      COPY_TEXT('bfd_signed_vma');
+   ENDIF;
+   match_pos := SEARCH_QUIETLY('@bfd_ufile_ptr@', FORWARD, EXACT, rang);
+   IF match_pos <> 0 THEN;
+      POSITION(BEGINNING_OF(match_pos));
+      ERASE(match_pos);
+      COPY_TEXT('bfd_vma');
+   ENDIF;
+   match_pos := SEARCH_QUIETLY('@supports_plugins@', FORWARD, EXACT, rang);
    IF match_pos <> 0 THEN;
       POSITION(BEGINNING_OF(match_pos));
       ERASE(match_pos);


                 reply	other threads:[~2022-08-01  1:08 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220801010850.55A253858412@sourceware.org \
    --to=amodra@sourceware.org \
    --cc=bfd-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).