Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Patrick Palka <patrick@parcs.ath.cx>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] Avoid invoking undefined behavior when initializing CRC table
Date: Mon, 28 Dec 2015 11:53:00 -0000	[thread overview]
Message-ID: <568122B4.7030502@redhat.com> (raw)
In-Reply-To: <alpine.DEB.2.20.9.1512272315120.19987@idea>

On 12/28/2015 04:15 AM, Patrick Palka wrote:
> On Sun, 27 Dec 2015, Patrick Palka wrote:
> 
>> When I built GDB with (an older snapshot of) GCC 6 I get the following
>> error:
>>
>> .../binutils-gdb/gdb/gdbserver/server.c: In function ‘crc32’:
>> .../binutils-gdb/gdb/gdbserver/server.c:1895:15: error: iteration 128 invokes undefined behavior [-Werror=aggressive-loop-optimizations]
>>    for (c = i << 24, j = 8; j > 0; --j)
>>               ^
>> .../binutils-gdb/gdb/gdbserver/server.c:1893:7: note: within this loop
>>       for (i = 0; i < 256; i++)
>>       ^
>> This error seems to be correct.  When the variable "int i" is >= 128,
>> the computation "i << 24" overflows for 32-bit signed int.
>>
>> To avoid shifting into the sign bit, this patch makes the variables i
>> (and j, because why not) have type unsigned int instead.
>>
>> (Alternatively, I can just define this local crc32 function in terms of
>> libiberty's xcrc32.  Any reason not to?

Just history.  gdbserver only started linking with libiberty in
2014 (0b04e52316) and the gdbserver crc32 code predates that.

> xcrc32 seems to be
>> based off of GDB's crc32 implementation.  Its documentation even
>> refers to it!)
> 
> And here's a rough diff that defines crc32 in terms of xcrc32:
> 

That looks good.  Tom did the same on the GDB side in 85ec6ce7d5 (2013).

Just in case, please make sure testing against gdbserver doesn't regress:

  $ make check -j8 RUNTESTFLAGS="--target_board=native-gdbserver" FORCE_PARALLEL=1

particularly, the compare-sections command.  We have a test which covers it:

  $ make check RUNTESTFLAGS="--target_board=native-gdbserver compare-sections.exp"

Thanks,
Pedro Alves


  reply	other threads:[~2015-12-28 11:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-28  4:10 Patrick Palka
2015-12-28  4:15 ` Patrick Palka
2015-12-28 11:53   ` Pedro Alves [this message]
2015-12-28 16:22     ` [PATCH] [COMMITTED] Use libiberty's crc32 implementation in gdbserver Patrick Palka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=568122B4.7030502@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=patrick@parcs.ath.cx \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox