git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: git@vger.kernel.org
Cc: Duy Nguyen <pclouds@gmail.com>,
	Christian Couder <christian.couder@gmail.com>
Subject: [PATCH 0/2] compiling with -fsanitize=undefined
Date: Tue, 29 Dec 2015 01:34:49 -0500	[thread overview]
Message-ID: <20151229063449.GA28755@sigill.intra.peff.net> (raw)

I was playing around with the new-ish "-fsanitize=undefined" compiler
flag, and it detected a few problems:

  1. We sometimes bit-shift signed constants too far (fixed by the first
     patch).

  2. We have some unaligned memory accesses that presumably work OK on
     x86, but would blow up on ARM or other platforms (I didn't test).

The latter looks like it's in the untracked cache code (Duy and
Christian cc'd). Running t7063 gets me this:

dir.c:2631:45: runtime error: member access within misaligned address 0x7f19806ff185 for type 'const struct ondisk_untracked_cache', which requires 4 byte alignment
0x7f19806ff185: note: pointer points here
 31 33 29 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00
             ^

We also do unaligned loads in the get_be* functions, but only on x86 and
similar platforms.  I'm counting these as a false positive, since it is
presumably OK there. The second patch makes it easier to squelch these.

I also got false positives from feeding NULL to qsort(). This is
technically wrong, but OK in practice when we tell it we have zero
elements. Compiling with INTERNAL_QSORT silences these (and if somebody
is on a platform where their qsort() segfaults, it's what I'd tell them
to use).

So if you want to play along at home, my build is something like:

  make \
    CC=clang \
    INTERNAL_QSORT=YesPlease \
    CFLAGS='-O2 -g -fsanitize=undefined -fno-sanitize-recover=undefined -DNO_UNALIGNED_LOADS' \
    test

and it passes except for t7063.

The patches are:

  [1/2]: avoid shifting signed integers 31 bits
  [2/2]: bswap: add NO_UNALIGNED_LOADS define

-Peff

             reply	other threads:[~2015-12-29  6:35 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-29  6:34 Jeff King [this message]
2015-12-29  6:35 ` [PATCH 1/2] avoid shifting signed integers 31 bits Jeff King
2015-12-30  0:09   ` Junio C Hamano
2015-12-30  4:25     ` Jeff King
2015-12-31  5:10   ` Duy Nguyen
2015-12-31  5:20     ` Jeff King
2016-01-04 17:52       ` Junio C Hamano
2016-01-04 23:32         ` Jeff King
2015-12-29  6:36 ` [PATCH 2/2] bswap: add NO_UNALIGNED_LOADS define Jeff King
2015-12-29  6:42   ` Eric Sunshine
2015-12-29  6:45     ` Jeff King
2015-12-29  6:44 ` [PATCH 0/2] compiling with -fsanitize=undefined Jeff King

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=20151229063449.GA28755@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=pclouds@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).