From: Alan Modra Date: Sun, 31 Jul 2022 09:55:32 +0000 (+0930) Subject: PR29348, BFD_VMA_FMT wrong X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=1a5178fe284547ef2abd8ae66588c9999d61c524;p=binutils-gdb.git 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. --- 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 #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 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@ -#define BFD_HOST_64BIT_LONG @BFD_HOST_64BIT_LONG@ - #include #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 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}" = "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 + #include + 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 + #include + 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);