From 242a115951fe55e62036bac555017eb817ca1aa6 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Thu, 28 Mar 2019 16:53:32 +1030 Subject: PR24392, Clang warning Wtautological-constant-out-of-range-compare PR 24392 * configure.ac: Invoke AC_CHECK_SIZEOF(int). * configure: Regenerate. * coffgen.c (coff_get_reloc_upper_bound): Replace gcc diagnostic workaround with SIZEOF_LONG vs. SIZEOF_INT check. * elf.c (_bfd_elf_get_reloc_upper_bound): Likewise. * elf64-sparc.c (elf64_sparc_get_reloc_upper_bound): Likewise. * mach-o.c (bfd_mach_o_get_reloc_upper_bound): Likewise. --- bfd/ChangeLog | 11 +++++++++++ bfd/coffgen.c | 9 ++------- bfd/configure | 33 +++++++++++++++++++++++++++++++++ bfd/configure.ac | 1 + bfd/elf.c | 10 ++-------- bfd/elf64-sparc.c | 9 ++------- bfd/mach-o.c | 9 ++------- 7 files changed, 53 insertions(+), 29 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 1225e3c..4dd3f27 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,14 @@ +2019-03-28 Alan Modra + + PR 24392 + * configure.ac: Invoke AC_CHECK_SIZEOF(int). + * configure: Regenerate. + * coffgen.c (coff_get_reloc_upper_bound): Replace gcc diagnostic + workaround with SIZEOF_LONG vs. SIZEOF_INT check. + * elf.c (_bfd_elf_get_reloc_upper_bound): Likewise. + * elf64-sparc.c (elf64_sparc_get_reloc_upper_bound): Likewise. + * mach-o.c (bfd_mach_o_get_reloc_upper_bound): Likewise. + 2019-03-21 Jim Wilson PR 24365 diff --git a/bfd/coffgen.c b/bfd/coffgen.c index ccf4b43..139ff97 100644 --- a/bfd/coffgen.c +++ b/bfd/coffgen.c @@ -2007,10 +2007,6 @@ coff_get_normalized_symtab (bfd *abfd) return internal; } -#if GCC_VERSION >= 4003 -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wtype-limits" -#endif long coff_get_reloc_upper_bound (bfd *abfd, sec_ptr asect) { @@ -2019,16 +2015,15 @@ coff_get_reloc_upper_bound (bfd *abfd, sec_ptr asect) bfd_set_error (bfd_error_invalid_operation); return -1; } +#if SIZEOF_LONG == SIZEOF_INT if (asect->reloc_count >= LONG_MAX / sizeof (arelent *)) { bfd_set_error (bfd_error_file_too_big); return -1; } +#endif return (asect->reloc_count + 1) * sizeof (arelent *); } -#if GCC_VERSION >= 4003 -# pragma GCC diagnostic pop -#endif asymbol * coff_make_empty_symbol (bfd *abfd) diff --git a/bfd/configure b/bfd/configure index 8d6c94a..202ef20 100755 --- a/bfd/configure +++ b/bfd/configure @@ -13367,6 +13367,39 @@ cat >>confdefs.h <<_ACEOF _ACEOF +# The cast to long int works around a bug in the HP C Compiler +# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects +# declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'. +# This bug is HP SR number 8606223364. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking size of int" >&5 +$as_echo_n "checking size of int... " >&6; } +if ${ac_cv_sizeof_int+:} false; then : + $as_echo_n "(cached) " >&6 +else + if ac_fn_c_compute_int "$LINENO" "(long int) (sizeof (int))" "ac_cv_sizeof_int" "$ac_includes_default"; then : + +else + if test "$ac_cv_type_int" = yes; then + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error 77 "cannot compute sizeof (int) +See \`config.log' for more details" "$LINENO" 5; } + else + ac_cv_sizeof_int=0 + fi +fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_sizeof_int" >&5 +$as_echo "$ac_cv_sizeof_int" >&6; } + + + +cat >>confdefs.h <<_ACEOF +#define SIZEOF_INT $ac_cv_sizeof_int +_ACEOF + + if test "x${ac_cv_sizeof_void_p}" = "x8"; then host64=true diff --git a/bfd/configure.ac b/bfd/configure.ac index 5f02c41..4cd946d 100644 --- a/bfd/configure.ac +++ b/bfd/configure.ac @@ -189,6 +189,7 @@ AC_TYPE_LONG_DOUBLE AC_CHECK_TYPES([long long], [AC_CHECK_SIZEOF(long long)]) AC_CHECK_SIZEOF(void *) AC_CHECK_SIZEOF(long) +AC_CHECK_SIZEOF(int) if test "x${ac_cv_sizeof_void_p}" = "x8"; then host64=true diff --git a/bfd/elf.c b/bfd/elf.c index 73fb869..13f96e8 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -8268,25 +8268,19 @@ _bfd_elf_get_dynamic_symtab_upper_bound (bfd *abfd) return symtab_size; } -#if GCC_VERSION >= 4003 -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wtype-limits" -#endif long _bfd_elf_get_reloc_upper_bound (bfd *abfd ATTRIBUTE_UNUSED, sec_ptr asect) { - +#if SIZEOF_LONG == SIZEOF_INT if (asect->reloc_count >= LONG_MAX / sizeof (arelent *)) { bfd_set_error (bfd_error_file_too_big); return -1; } +#endif return (asect->reloc_count + 1) * sizeof (arelent *); } -#if GCC_VERSION >= 4003 -# pragma GCC diagnostic pop -#endif /* Canonicalize the relocs. */ diff --git a/bfd/elf64-sparc.c b/bfd/elf64-sparc.c index f523ce7..55a1db9 100644 --- a/bfd/elf64-sparc.c +++ b/bfd/elf64-sparc.c @@ -34,23 +34,18 @@ section can represent up to two relocs, we must tell the user to allocate more space. */ -#if GCC_VERSION >= 4003 -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wtype-limits" -#endif static long elf64_sparc_get_reloc_upper_bound (bfd *abfd ATTRIBUTE_UNUSED, asection *sec) { +#if SIZEOF_LONG == SIZEOF_INT if (sec->reloc_count >= LONG_MAX / 2 / sizeof (arelent *)) { bfd_set_error (bfd_error_file_too_big); return -1; } +#endif return (sec->reloc_count * 2 + 1) * sizeof (arelent *); } -#if GCC_VERSION >= 4003 -# pragma GCC diagnostic pop -#endif static long elf64_sparc_get_dynamic_reloc_upper_bound (bfd *abfd) diff --git a/bfd/mach-o.c b/bfd/mach-o.c index a9ca313..122a0c2 100644 --- a/bfd/mach-o.c +++ b/bfd/mach-o.c @@ -1417,24 +1417,19 @@ bfd_mach_o_write_dyld_info (bfd *abfd, bfd_mach_o_load_command *command) return TRUE; } -#if GCC_VERSION >= 4003 -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wtype-limits" -#endif long bfd_mach_o_get_reloc_upper_bound (bfd *abfd ATTRIBUTE_UNUSED, asection *asect) { +#if SIZEOF_LONG == SIZEOF_INT if (asect->reloc_count >= LONG_MAX / sizeof (arelent *)) { bfd_set_error (bfd_error_file_too_big); return -1; } +#endif return (asect->reloc_count + 1) * sizeof (arelent *); } -#if GCC_VERSION >= 4003 -# pragma GCC diagnostic pop -#endif /* In addition to the need to byte-swap the symbol number, the bit positions of the fields in the relocation information vary per target endian-ness. */ -- cgit v1.1