From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by sourceware.org (Postfix) with ESMTPS id 638C9384B0D6 for ; Sun, 31 Jul 2022 23:59:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 638C9384B0D6 Received: by mail-pg1-x532.google.com with SMTP id bf13so8284544pgb.11 for ; Sun, 31 Jul 2022 16:59:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition; bh=E2shmb6dUbb5fNJ8HqvilZRRs86VJkSQdmWyz2OiSoo=; b=6aCcPFnnEIArF1InXbrbiAfWUDMKHFr9XrETKGlYYOCPxwTwnbVtSFOZ/JAUF2IzA8 EMnaBWyW1t/jjVf1DPFD874MxMfufNj2JWAM89r7iqi1ri0pv+aoL64VTTS/40LwrnnK ye685j15iLBojuRlL+qvp5thCmVh1e2t6DHm+P9QJs0K/Ev7vYEd4AU/WCp1cfdHH8Fq Kqul5Bx8zzDhiug7WEglrlo44NGL9Er1ES8nJfRPsZ4c1fy2ELV+zaKtNEmaam2ZxZ4c CtFtnMeIE7hol/y5cwmcTG9IQYOkPIXBe3Q1BSDv2dKS5ezriMOc9tB9xsYQ4VP92mNy VYVQ== X-Gm-Message-State: AJIora8Ipz1T5DggdTal+JrDKgDbn+oqw7yTMDnoQ+Dl12t6bMDat0mN FL4zZ3/u9nCp24kaCXBbaFAo8ac8SNw= X-Google-Smtp-Source: AGRyM1s6M/gH35sAUmnpZ/nrgankp3/E46WZzpzT+Y0BOIl0IXmRi5vAP9JNeCcxkZwalTf+LTobqg== X-Received: by 2002:a63:6888:0:b0:3fe:49fc:3be3 with SMTP id d130-20020a636888000000b003fe49fc3be3mr10877878pgc.182.1659311957114; Sun, 31 Jul 2022 16:59:17 -0700 (PDT) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:18bd:5310:8fa5:2ea1]) by smtp.gmail.com with ESMTPSA id d6-20020a170902654600b0016dc6279ab7sm8007499pln.149.2022.07.31.16.59.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Jul 2022 16:59:16 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 2ED1111402AE; Mon, 1 Aug 2022 09:29:14 +0930 (ACST) Date: Mon, 1 Aug 2022 09:29:14 +0930 From: Alan Modra To: binutils@sourceware.org Subject: PR29348, BFD_VMA_FMT wrong Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3036.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 31 Jul 2022 23:59:24 -0000 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); -- Alan Modra Australia Development Lab, IBM