From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Thomas Huth <thuth@redhat.com>
Cc: Richard Schmitt <richard.schmitt@starlab.io>,
"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Subject: Re: Unit Test Aborts when building with -ftrapv compiler option
Date: Fri, 9 Feb 2024 09:41:30 +0000 [thread overview]
Message-ID: <ZcXzSjbO0AMuzqGZ@redhat.com> (raw)
In-Reply-To: <12a41472-5d91-4e8c-9cc1-e255313791c9@redhat.com>
On Fri, Feb 09, 2024 at 08:02:49AM +0100, Thomas Huth wrote:
> On 08/02/2024 20.23, Richard Schmitt wrote:
> > In an attempt to build qemu with hardened gcc compiler options, we
> > specified the -ftrapv switch rather than the -fwrapv switch. The
> > switches define the behavior of integer overflows. -ftrapv causes an
> > abort on integer overflow, -fwrapv causes overflows to simply wrap
> > without any error indication. Wrapping overflows can result in
> > unexpected behavior and therefore, hardenened builds typically recommend
> > trapping overflows.
> >
> > The abort occurs when running the “test-string-input-verifier” test and
> > begins at line 129 of the source:
> >
> > v = visitor_input_test_init(data,
> >
> > “-9223372036854775808, 9223372036854775807”);
> >
> > check_ilist(v, expect3, ARRAY_SIZE(expect3);
> >
> > Where expect3 is declared as:
> >
> > int64_t expect3[] = { INT64_MIN, INT64_MAX };
> >
> > The actual abort occurs in “string-input-visitor.c” line 209:
> >
> > *obj = siv->rangeNext.i64++;
> >
> > The test, as coded, will generate an overflow. Using the -fwrapv
> > compiler option hides the overflow.
> >
> > My question, is it the intent of the qemu community to rely on the
> > overflow wrap behavior or should this be considered an issue and added
> > as such in gitlab’s issue list?
>
> As far as I understood, QEMU deliberately depends on this behavior - at
> least we require -fWrapv in meson.build:
>
> # We use -fwrapv to tell the compiler that we require a C dialect where
> # left shift of signed integers is well defined and has the expected
> # 2s-complement style results. (Both clang and gcc agree that it
> # provides these semantics.)
Introduced by this:
commit 2d31515bc0880a1cea86ce638d2a109f4f4e6f7d
Author: Peter Maydell <peter.maydell@linaro.org>
Date: Mon Sep 12 14:10:08 2016 +0100
configure: Always compile with -fwrapv
QEMU's code relies on left shifts of signed integers always
being defined behaviour with the obvious 2s-complement
semantics. The only way to tell the compiler (and any
associated undefined-behaviour sanitizer) that we require a
C dialect with these semantics is to use the -fwrapv option.
This is a bit of a heavy hammer for the job as it also gives
us guaranteed semantics on integer arithmetic overflow which
in theory we don't require.
In an ideal world this would allow us to drop the warning
flag -Wno-shift-negative-value, but we must retain this to
avoid spurious warnings on clang versions predating the
fix to https://llvm.org/bugs/show_bug.cgi?id=25552.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
Message-id: 1473685808-9629-1-git-send-email-peter.maydell@linaro.org
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
prev parent reply other threads:[~2024-02-09 9:42 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-08 19:23 Unit Test Aborts when building with -ftrapv compiler option Richard Schmitt
2024-02-09 7:02 ` Thomas Huth
2024-02-09 9:41 ` Daniel P. Berrangé [this message]
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=ZcXzSjbO0AMuzqGZ@redhat.com \
--to=berrange@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.schmitt@starlab.io \
--cc=thuth@redhat.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).