From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1062) id 3D1703858023; Mon, 1 Aug 2022 00:01:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3D1703858023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Alan Modra To: bfd-cvs@sourceware.org Subject: [binutils-gdb] PR29348, BFD_VMA_FMT wrong X-Act-Checkin: binutils-gdb X-Git-Author: Alan Modra X-Git-Refname: refs/heads/master X-Git-Oldrev: df0e73ff9307251d179aa4158347deccc9576b85 X-Git-Newrev: 1a5178fe284547ef2abd8ae66588c9999d61c524 Message-Id: <20220801000102.3D1703858023@sourceware.org> Date: Mon, 1 Aug 2022 00:01:02 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 01 Aug 2022 00:01:02 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D1a5178fe2845= 47ef2abd8ae66588c9999d61c524 commit 1a5178fe284547ef2abd8ae66588c9999d61c524 Author: Alan Modra Date: Sun Jul 31 19:25:32 2022 +0930 PR29348, BFD_VMA_FMT wrong =20 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. =20 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. =20 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. 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 =3D @AUTOCONF@ AUTOHEADER =3D @AUTOHEADER@ AUTOMAKE =3D @AUTOMAKE@ AWK =3D @AWK@ -BFD_HOST_64BIT_LONG =3D @BFD_HOST_64BIT_LONG@ +BFD_INT64_FMT =3D @BFD_INT64_FMT@ CATALOGS =3D @CATALOGS@ CATOBJEXT =3D @CATOBJEXT@ CC =3D @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@ =20 -#define BFD_HOST_64BIT_LONG @BFD_HOST_64BIT_LONG@ - #include =20 #if BFD_ARCH_SIZE >=3D 64 @@ -101,42 +99,34 @@ typedef struct bfd bfd; =20 #ifdef BFD64 =20 +/* 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 compatib= le + (as parameters, in assignment, etc). */ typedef int64_t bfd_signed_vma; + typedef uint64_t bfd_size_type; typedef uint64_t symvalue; =20 -#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@ =20 -#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) =20 #else /* not BFD64 */ =20 -/* 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 compatib= le - (as parameters, in assignment, etc). */ typedef long bfd_signed_vma; - typedef unsigned long symvalue; typedef unsigned long bfd_size_type; =20 -/* 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) =20 diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index 2d6e1bbc0b0..bbe19288520 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@ =20 -#define BFD_HOST_64BIT_LONG @BFD_HOST_64BIT_LONG@ - #include =20 #if BFD_ARCH_SIZE >=3D 64 @@ -108,42 +106,34 @@ typedef struct bfd bfd; =20 #ifdef BFD64 =20 +/* 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 compatib= le + (as parameters, in assignment, etc). */ typedef int64_t bfd_signed_vma; + typedef uint64_t bfd_size_type; typedef uint64_t symvalue; =20 -#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@ =20 -#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) =20 #else /* not BFD64 */ =20 -/* 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 compatib= le - (as parameters, in assignment, etc). */ typedef long bfd_signed_vma; - typedef unsigned long symvalue; typedef unsigned long bfd_size_type; =20 -/* 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) =20 diff --git a/bfd/configure b/bfd/configure index 590986efb61..35e0b78405b 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}" =3D "x8"; then host64=3Dtrue fi =20 -BFD_HOST_64BIT_LONG=3D0 -if test "x${ac_cv_sizeof_long}" =3D "x8"; then - BFD_HOST_64BIT_LONG=3D1 -fi - - - # Put a plausible default for CC_FOR_BUILD in Makefile. if test -z "$CC_FOR_BUILD"; then if test "x$cross_compiling" =3D "xno"; then @@ -13041,6 +13034,39 @@ $as_echo "#define HAVE_HIDDEN 1" >>confdefs.h =20 fi =20 +{ $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 + #include + extern char PRId64_probe[sizeof PRId64 =3D=3D sizeof "${style}d" ? = 1 : -1]; + +int +main () +{ + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + bfd_cv_int64_fmt=3D${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=3D\"$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 suppo= rt" >&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}" =3D "x8"; then host64=3Dtrue fi =20 -BFD_HOST_64BIT_LONG=3D0 -if test "x${ac_cv_sizeof_long}" =3D "x8"; then - BFD_HOST_64BIT_LONG=3D1 -fi - -AC_SUBST(BFD_HOST_64BIT_LONG) - BFD_CC_FOR_BUILD =20 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 =3D yes; then [Define if your compiler supports hidden visibility.]) fi =20 +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 + #include + extern char PRId64_probe[sizeof PRId64 =3D=3D sizeof "${style}d" ? = 1 : -1]; + ]])], [bfd_cv_int64_fmt=3D${style}], [])] + done) +BFD_INT64_FMT=3D\"$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=3Dno 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 :=3D SEARCH_QUIETLY('@BFD_HOST_64BIT_LONG@', FORWARD, EXACT, = rang); + match_pos :=3D 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 :=3D 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 :=3D SEARCH_QUIETLY('@BFD_HOST_64BIT_LONG@', FORWARD, EXACT, = rang); + match_pos :=3D SEARCH_QUIETLY('@bfd_default_target_size@', FORWARD, EXA= CT, rang); + IF match_pos <> 0 THEN; + POSITION(BEGINNING_OF(match_pos)); + ERASE(match_pos); + COPY_TEXT('32'); + ENDIF; + match_pos :=3D 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 :=3D 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 :=3D 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 :=3D SEARCH_QUIETLY('@supports_plugins@', FORWARD, EXACT, ran= g); IF match_pos <> 0 THEN; POSITION(BEGINNING_OF(match_pos)); ERASE(match_pos);