* [Qemu-devel] [PATCH] configure: fix sanitizers' test program to mend ASan detection
@ 2018-02-21 1:03 Emilio G. Cota
2018-02-21 9:12 ` Marc-André Lureau
0 siblings, 1 reply; 3+ messages in thread
From: Emilio G. Cota @ 2018-02-21 1:03 UTC (permalink / raw)
To: qemu-devel; +Cc: Marc-André Lureau, Paolo Bonzini
Commit 218bb57 ("build-sys: check static linking of UBSAN", 2018-02-13)
adds a small test program to check whether ubsan works even when
configuring with --static. This added program is used to
detect all sanitizers, which breaks ASan's detection since the
compilation fails with -fsanitize=address, at least with gcc 5.4.0
and 7.2.0:
qemu-conf.c: In function ‘main’:
qemu-conf.c:3:20: error: integer overflow in expression [-Werror=overflow]
return INT32_MIN / -1;
^
cc1: all warnings being treated as errors
Fix it by:
- Changing the test program to one that incurs undefined behaviour that isn't
detected at compile-time, even with -fsanitize=address.
- To be extra safe (since compilers might evolve and eventually figure out
the UB at compile-time), use this newly-added test only when checking
for UBSan; use the skeleton otherwise.
Signed-off-by: Emilio G. Cota <cota@braap.org>
---
configure | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/configure b/configure
index 913e148..56f647f 100755
--- a/configure
+++ b/configure
@@ -5306,13 +5306,13 @@ fi
##########################################
# checks for sanitizers
-# we could use a simple skeleton for flags checks, but this also
-# detect the static linking issue of ubsan, see also:
+# Use this program to detect the static linking issue of ubsan; see
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84285
cat > $TMPC << EOF
-#include <stdint.h>
-int main(void) {
- return INT32_MIN / -1;
+int main(int argc, char **argv) {
+ int k = 0x7fffffff;
+ k += argc;
+ return 0;
}
EOF
@@ -5322,12 +5322,16 @@ have_asan_iface_h=no
have_asan_iface_fiber=no
if test "$sanitizers" = "yes" ; then
+ if compile_prog "$CPU_CFLAGS -Werror -fsanitize=undefined" ""; then
+ have_ubsan=yes
+ fi
+
+ # Use the skeleton for all other sanitizer checks
+ write_c_skeleton
+
if compile_prog "$CPU_CFLAGS -Werror -fsanitize=address" ""; then
have_asan=yes
fi
- if compile_prog "$CPU_CFLAGS -Werror -fsanitize=undefined" ""; then
- have_ubsan=yes
- fi
if check_include "sanitizer/asan_interface.h" ; then
have_asan_iface_h=yes
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] configure: fix sanitizers' test program to mend ASan detection
2018-02-21 1:03 [Qemu-devel] [PATCH] configure: fix sanitizers' test program to mend ASan detection Emilio G. Cota
@ 2018-02-21 9:12 ` Marc-André Lureau
2018-02-21 19:13 ` Emilio G. Cota
0 siblings, 1 reply; 3+ messages in thread
From: Marc-André Lureau @ 2018-02-21 9:12 UTC (permalink / raw)
To: Emilio G. Cota; +Cc: qemu-devel, Paolo Bonzini
Hi
On Wed, Feb 21, 2018 at 2:03 AM, Emilio G. Cota <cota@braap.org> wrote:
> Commit 218bb57 ("build-sys: check static linking of UBSAN", 2018-02-13)
> adds a small test program to check whether ubsan works even when
> configuring with --static. This added program is used to
> detect all sanitizers, which breaks ASan's detection since the
> compilation fails with -fsanitize=address, at least with gcc 5.4.0
> and 7.2.0:
>
> qemu-conf.c: In function ‘main’:
> qemu-conf.c:3:20: error: integer overflow in expression [-Werror=overflow]
> return INT32_MIN / -1;
> ^
> cc1: all warnings being treated as errors
I sent a patch a few days ago:
"[PATCH 1/6] build-sys: fix -fsanitize=address check"
>
> Fix it by:
>
> - Changing the test program to one that incurs undefined behaviour that isn't
> detected at compile-time, even with -fsanitize=address.
>
> - To be extra safe (since compilers might evolve and eventually figure out
> the UB at compile-time), use this newly-added test only when checking
> for UBSan; use the skeleton otherwise.
>
> Signed-off-by: Emilio G. Cota <cota@braap.org>
> ---
> configure | 20 ++++++++++++--------
> 1 file changed, 12 insertions(+), 8 deletions(-)
>
> diff --git a/configure b/configure
> index 913e148..56f647f 100755
> --- a/configure
> +++ b/configure
> @@ -5306,13 +5306,13 @@ fi
> ##########################################
> # checks for sanitizers
>
> -# we could use a simple skeleton for flags checks, but this also
> -# detect the static linking issue of ubsan, see also:
> +# Use this program to detect the static linking issue of ubsan; see
> # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84285
> cat > $TMPC << EOF
> -#include <stdint.h>
> -int main(void) {
> - return INT32_MIN / -1;
> +int main(int argc, char **argv) {
> + int k = 0x7fffffff;
> + k += argc;
> + return 0;
> }
> EOF
>
> @@ -5322,12 +5322,16 @@ have_asan_iface_h=no
> have_asan_iface_fiber=no
>
> if test "$sanitizers" = "yes" ; then
> + if compile_prog "$CPU_CFLAGS -Werror -fsanitize=undefined" ""; then
> + have_ubsan=yes
> + fi
> +
> + # Use the skeleton for all other sanitizer checks
> + write_c_skeleton
> +
> if compile_prog "$CPU_CFLAGS -Werror -fsanitize=address" ""; then
> have_asan=yes
> fi
> - if compile_prog "$CPU_CFLAGS -Werror -fsanitize=undefined" ""; then
> - have_ubsan=yes
> - fi
>
> if check_include "sanitizer/asan_interface.h" ; then
> have_asan_iface_h=yes
> --
> 2.7.4
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] configure: fix sanitizers' test program to mend ASan detection
2018-02-21 9:12 ` Marc-André Lureau
@ 2018-02-21 19:13 ` Emilio G. Cota
0 siblings, 0 replies; 3+ messages in thread
From: Emilio G. Cota @ 2018-02-21 19:13 UTC (permalink / raw)
To: Marc-André Lureau; +Cc: qemu-devel, Paolo Bonzini
On Wed, Feb 21, 2018 at 10:12:28 +0100, Marc-André Lureau wrote:
> I sent a patch a few days ago:
> "[PATCH 1/6] build-sys: fix -fsanitize=address check"
Ouch, I missed that. Please disregard my patch.
Thanks,
Emilio
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-02-21 19:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-21 1:03 [Qemu-devel] [PATCH] configure: fix sanitizers' test program to mend ASan detection Emilio G. Cota
2018-02-21 9:12 ` Marc-André Lureau
2018-02-21 19:13 ` Emilio G. Cota
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).