[PATCH] gdb: Workaround stringop-overread warning in debuginfod-support.c on powerpc64

Mark Wielaard mark@klomp.org
Tue May 31 10:51:28 GMT 2022


Hi Pedro,

On Tue, 2022-05-31 at 10:46 +0100, Pedro Alves wrote:
> On 2022-05-31 10:05, Mark Wielaard wrote:
> > +	  /* g++ 11.2.1 on s390x, g++q 11.3.1 on ppc64le and g++ 11 on
> > +	     hppa seem convinced url_view might be of SIZE_MAX length.
> > +	     And so complains because the length of an array can only
> > +	     be PTRDIFF_MAX.  */
> 
> I wonder whether sticking in an assert so that the compiler knows the
> size of array, would make the warning go away:

If only we had the try buildbots running already, then we could more
easily try (because one of them, fedora-s390x, does show this issue).
I'll try (pun intended) to get that up by next week.

> diff --git c/gdb/debuginfod-support.c w/gdb/debuginfod-support.c
> index 6dc08fc29b6..d6fab39eac8 100644
> --- c/gdb/debuginfod-support.c
> +++ w/gdb/debuginfod-support.c
> @@ -187,6 +187,8 @@ debuginfod_is_enabled ()
>                     "from the following URLs:\n"));
>  
>        gdb::string_view url_view (urls);
> +      gdb_assert (url_view.size () < PTRDIFF_MAX);
> +
>        while (true)
>         {
>           size_t off = url_view.find_first_not_of (' ');

I tried by hand, but that does result in the same warning (with the
DIAGNOSTIC_IGNORE_STRINGOP_OVERREAD removed):

  CXX    debuginfod-support.o
In file included from /usr/include/c++/11/string:40,
                 from ../../binutils-gdb/gdb/../gdbsupport/ptid.h:36,
                 from ../../binutils-gdb/gdb/../gdbsupport/common-defs.h:198,
                 from ../../binutils-gdb/gdb/defs.h:28,
                 from ../../binutils-gdb/gdb/debuginfod-support.c:19:
In static member function ‘static constexpr const char_type* std::char_traits<char>::find(const char_type*, std::size_t, const char_type&)’,
    inlined from ‘constexpr std::basic_string_view<_CharT, _Traits>::size_type std::basic_string_view<_CharT, _Traits>::find(_CharT, std::basic_string_view<_CharT, _Traits>::size_type) const [with _CharT = char; _Traits = std::char_traits<char>]’ at /usr/include/c++/11/bits/string_view.tcc:87:41,
    inlined from ‘constexpr std::basic_string_view<_CharT, _Traits>::size_type std::basic_string_view<_CharT, _Traits>::find_first_of(_CharT, std::basic_string_view<_CharT, _Traits>::size_type) const [with _CharT = char; _Traits = std::char_traits<char>]’ at /usr/include/c++/11/string_view:431:26,
    inlined from ‘bool debuginfod_is_enabled()’ at ../../binutils-gdb/gdb/debuginfod-support.c:197:33:
/usr/include/c++/11/bits/char_traits.h:413:62: error: ‘void* __builtin_memchr(const void*, int, long unsigned int)’ specified bound 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Werror=stringop-overread]
  413 |         return static_cast<const char_type*>(__builtin_memchr(__s, __a, __n));
      |                                              ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
cc1plus: all warnings being treated as errors
make[1]: *** [Makefile:1895: debuginfod-support.o] Error 1


More information about the Gdb-patches mailing list