CVS commit: src/tests/lib/libc/misc
Module Name:src Committed By: christos Date: Thu Jan 30 00:42:58 UTC 2020 Modified Files: src/tests/lib/libc/misc: Makefile Log Message: hack for clang/powerpc To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/tests/lib/libc/misc/Makefile Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/lib/libc/misc/Makefile diff -u src/tests/lib/libc/misc/Makefile:1.5 src/tests/lib/libc/misc/Makefile:1.6 --- src/tests/lib/libc/misc/Makefile:1.5 Sun Sep 29 19:45:00 2019 +++ src/tests/lib/libc/misc/Makefile Wed Jan 29 19:42:58 2020 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.5 2019/09/29 23:45:00 mrg Exp $ +# $NetBSD: Makefile,v 1.6 2020/01/30 00:42:58 christos Exp $ .include @@ -28,6 +28,8 @@ CWARNFLAGS.clang+= -Wno-nullability-comp .endif COPTS.t_ubsan.c += -Wno-stack-protector COPTS.t_ubsanxx.cpp += -Wno-stack-protector +COPTS.ubsan.c+=${${ACTIVE_CC} == "clang" && ${MACHINE_ARCH} == "powerpc":? -O0 :} + .if defined(HAVE_GCC) && ${HAVE_GCC} >= 7 && ${ACTIVE_CC} == "gcc" COPTS.t_ubsan.c+= -Wno-int-in-bool-context
CVS commit: src/tests/lib/libc/misc
Module Name:src Committed By: kamil Date: Wed Feb 20 11:40:41 UTC 2019 Modified Files: src/tests/lib/libc/misc: t_ubsan.c Log Message: Unify the style of t_ubsan tests Apply similar change for load_invalid_value_bool in test_load_invalid_value_enum. Follow up of PR bin/53968 by Michael van Elst To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/tests/lib/libc/misc/t_ubsan.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/lib/libc/misc/t_ubsan.c diff -u src/tests/lib/libc/misc/t_ubsan.c:1.4 src/tests/lib/libc/misc/t_ubsan.c:1.5 --- src/tests/lib/libc/misc/t_ubsan.c:1.4 Wed Feb 20 09:50:09 2019 +++ src/tests/lib/libc/misc/t_ubsan.c Wed Feb 20 11:40:41 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ubsan.c,v 1.4 2019/02/20 09:50:09 kamil Exp $ */ +/* $NetBSD: t_ubsan.c,v 1.5 2019/02/20 11:40:41 kamil Exp $ */ /*- * Copyright (c) 2018 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2018\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_ubsan.c,v 1.4 2019/02/20 09:50:09 kamil Exp $"); +__RCSID("$NetBSD: t_ubsan.c,v 1.5 2019/02/20 11:40:41 kamil Exp $"); #include #include @@ -318,7 +318,7 @@ static void test_load_invalid_value_enum(void) { enum e { e1, e2, e3, e4 }; - volatile int a = atoi("10"); + volatile int a = INT_MAX - atoi("10"); volatile enum e E = *(REINTERPRET_CAST(volatile enum e*, )); raise((E == e1) ? SIGSEGV : SIGBUS);
CVS commit: src/tests/lib/libc/misc
Module Name:src Committed By: kamil Date: Wed Feb 20 09:50:09 UTC 2019 Modified Files: src/tests/lib/libc/misc: t_ubsan.c Log Message: Try to make load_invalid_value_bool portable to Big-Endian PR bin/53968 by Michael van Elst To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libc/misc/t_ubsan.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/lib/libc/misc/t_ubsan.c diff -u src/tests/lib/libc/misc/t_ubsan.c:1.3 src/tests/lib/libc/misc/t_ubsan.c:1.4 --- src/tests/lib/libc/misc/t_ubsan.c:1.3 Mon Feb 4 03:10:33 2019 +++ src/tests/lib/libc/misc/t_ubsan.c Wed Feb 20 09:50:09 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ubsan.c,v 1.3 2019/02/04 03:10:33 mrg Exp $ */ +/* $NetBSD: t_ubsan.c,v 1.4 2019/02/20 09:50:09 kamil Exp $ */ /*- * Copyright (c) 2018 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2018\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_ubsan.c,v 1.3 2019/02/04 03:10:33 mrg Exp $"); +__RCSID("$NetBSD: t_ubsan.c,v 1.4 2019/02/20 09:50:09 kamil Exp $"); #include #include @@ -295,7 +295,7 @@ UBSAN_TC_HEAD(load_invalid_value_bool, t static void test_load_invalid_value_bool(void) { - volatile int a = atoi("10"); + volatile int a = INT_MAX - atoi("10"); volatile bool b = *(REINTERPRET_CAST(volatile bool *, )); raise(b ? SIGSEGV : SIGBUS);
CVS commit: src/tests/lib/libc/misc
Module Name:src Committed By: mrg Date: Mon Feb 4 03:10:33 UTC 2019 Modified Files: src/tests/lib/libc/misc: Makefile t_ubsan.c Log Message: - revert previous to t_ubsan.c, it is desired behaviour. from kamil. - use -Wno-int-in-bool-context instead To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libc/misc/Makefile \ src/tests/lib/libc/misc/t_ubsan.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/lib/libc/misc/Makefile diff -u src/tests/lib/libc/misc/Makefile:1.2 src/tests/lib/libc/misc/Makefile:1.3 --- src/tests/lib/libc/misc/Makefile:1.2 Thu Aug 9 12:45:15 2018 +++ src/tests/lib/libc/misc/Makefile Mon Feb 4 03:10:33 2019 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.2 2018/08/09 12:45:15 christos Exp $ +# $NetBSD: Makefile,v 1.3 2019/02/04 03:10:33 mrg Exp $ .include @@ -27,4 +27,9 @@ CWARNFLAGS.clang+= -Wno-nullability-comp COPTS.t_ubsan.c += -Wno-stack-protector COPTS.t_ubsanxx.cpp += -Wno-stack-protector +.if defined(HAVE_GCC) && ${HAVE_GCC} == 7 && ${ACTIVE_CC} == "gcc" +COPTS.t_ubsan.c+= -Wno-int-in-bool-context +COPTS.t_ubsanxx.cpp+= -Wno-int-in-bool-context +.endif + .include Index: src/tests/lib/libc/misc/t_ubsan.c diff -u src/tests/lib/libc/misc/t_ubsan.c:1.2 src/tests/lib/libc/misc/t_ubsan.c:1.3 --- src/tests/lib/libc/misc/t_ubsan.c:1.2 Sun Feb 3 10:45:58 2019 +++ src/tests/lib/libc/misc/t_ubsan.c Mon Feb 4 03:10:33 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: t_ubsan.c,v 1.2 2019/02/03 10:45:58 mrg Exp $ */ +/* $NetBSD: t_ubsan.c,v 1.3 2019/02/04 03:10:33 mrg Exp $ */ /*- * Copyright (c) 2018 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2018\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_ubsan.c,v 1.2 2019/02/03 10:45:58 mrg Exp $"); +__RCSID("$NetBSD: t_ubsan.c,v 1.3 2019/02/04 03:10:33 mrg Exp $"); #include #include @@ -376,7 +376,7 @@ test_mul_overflow_signed(void) volatile int a = INT_MAX; volatile int b = atoi("2"); - raise((a && b) ? SIGSEGV : SIGBUS); + raise((a * b) ? SIGSEGV : SIGBUS); } UBSAN_TC_BODY(mul_overflow_signed, tc)
CVS commit: src/tests/lib/libc/misc
Module Name:src Committed By: christos Date: Thu Aug 9 12:45:15 UTC 2018 Modified Files: src/tests/lib/libc/misc: Makefile Log Message: Fix stack protector build. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libc/misc/Makefile Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/tests/lib/libc/misc/Makefile diff -u src/tests/lib/libc/misc/Makefile:1.1 src/tests/lib/libc/misc/Makefile:1.2 --- src/tests/lib/libc/misc/Makefile:1.1 Fri Aug 3 00:18:40 2018 +++ src/tests/lib/libc/misc/Makefile Thu Aug 9 08:45:15 2018 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.1 2018/08/03 04:18:40 kamil Exp $ +# $NetBSD: Makefile,v 1.2 2018/08/09 12:45:15 christos Exp $ .include @@ -24,5 +24,7 @@ CWARNFLAGS+= -Wno-return-type -Wno-stri CWARNFLAGS.clang+= -Wno-incompatible-pointer-types-discards-qualifiers CWARNFLAGS.clang+= -Wno-nullability-completeness .endif +COPTS.t_ubsan.c += -Wno-stack-protector +COPTS.t_ubsanxx.cpp += -Wno-stack-protector .include
CVS commit: src/tests/lib/libc/misc
Module Name:src Committed By: kamil Date: Fri Aug 3 04:18:40 UTC 2018 Added Files: src/tests/lib/libc/misc: Makefile t_ubsan.c t_ubsanxx.cpp Log Message: Import micro-UBSan ATF tests These tests are used only when a distribution is built without MKSANITIZER and without MKLIBCSANITIZER. They build the ubsan.c micro-implementation in userland as a standalone library (a .c file linked into tests). The code generation part emits symbols that are handled by uUBSan. Tested with Clang amd64 + i386 and GCC amd64 + i386. There are two sets of tests: C code generation and C++ code generation. There are various little differences that are handled with proper ifdefs. Clang 7svn has significantly more checks for Undefined Behavior than GCC 5.x. Some of the tests are or might be amd64 and/or i386 specific and are marked with proper ifdefs and comments according to the compiler documentation. To generate a diff of this commit: cvs rdiff -u -r0 -r1.1 src/tests/lib/libc/misc/Makefile \ src/tests/lib/libc/misc/t_ubsan.c src/tests/lib/libc/misc/t_ubsanxx.cpp Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Added files: Index: src/tests/lib/libc/misc/Makefile diff -u /dev/null src/tests/lib/libc/misc/Makefile:1.1 --- /dev/null Fri Aug 3 04:18:40 2018 +++ src/tests/lib/libc/misc/Makefile Fri Aug 3 04:18:40 2018 @@ -0,0 +1,28 @@ +# $NetBSD: Makefile,v 1.1 2018/08/03 04:18:40 kamil Exp $ + +.include + +TESTSDIR= ${TESTSBASE}/lib/libc/misc + +TESTS_C+= t_ubsan +TESTS_CXX+= t_ubsanxx + +.PATH: ${NETBSDSRCDIR}/common/lib/libc/misc +SRCS.t_ubsan= t_ubsan.c ubsan.c +SRCS.t_ubsanxx= t_ubsanxx.cpp ubsan.c + +.if ${MKSANITIZER:Uno} != "yes" && ${MKLIBCSANITIZER:Uno} != "yes" +# These tests are designed to be used against micro-UBSan only. +# micro-UBSan is used in these tests as a standalone libary only. +CPPFLAGS+= -DENABLE_TESTS +UBSAN_FLAGS= -fsanitize=undefined +UBSAN_FLAGS+= ${${ACTIVE_CC} == "clang" :? -fsanitize=integer :} +UBSAN_FLAGS+= ${${ACTIVE_CC} == "clang" :? -fsanitize=nullability :} +CFLAGS+= ${UBSAN_FLAGS} +CXXFLAGS+= ${UBSAN_FLAGS} +CWARNFLAGS+= -Wno-return-type -Wno-strict-aliasing +CWARNFLAGS.clang+= -Wno-incompatible-pointer-types-discards-qualifiers +CWARNFLAGS.clang+= -Wno-nullability-completeness +.endif + +.include Index: src/tests/lib/libc/misc/t_ubsan.c diff -u /dev/null src/tests/lib/libc/misc/t_ubsan.c:1.1 --- /dev/null Fri Aug 3 04:18:40 2018 +++ src/tests/lib/libc/misc/t_ubsan.c Fri Aug 3 04:18:40 2018 @@ -0,0 +1,913 @@ +/* $NetBSD: t_ubsan.c,v 1.1 2018/08/03 04:18:40 kamil Exp $ */ + +/*- + * Copyright (c) 2018 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + *notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + *notice, this list of conditions and the following disclaimer in the + *documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__COPYRIGHT("@(#) Copyright (c) 2018\ + The NetBSD Foundation, inc. All rights reserved."); +__RCSID("$NetBSD: t_ubsan.c,v 1.1 2018/08/03 04:18:40 kamil Exp $"); + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus +#include +#define UBSAN_TC(a) ATF_TEST_CASE(a) +#define UBSAN_TC_HEAD(a, b) ATF_TEST_CASE_HEAD(a) +#define UBSAN_TC_BODY(a, b) ATF_TEST_CASE_BODY(a) +#define UBSAN_CASES(a) ATF_INIT_TEST_CASES(a) +#define UBSAN_TEST_CASE(a, b) ATF_ADD_TEST_CASE(a, b) +#define UBSAN_MD_VAR(a, b, c) set_md_var(b, c) +#define REINTERPRET_CAST(__dt, __st) reinterpret_cast<__dt>(__st) +#define STATIC_CAST(__dt, __st) static_cast<__dt>(__st) +#else +#include +#define UBSAN_TC(a) ATF_TC(a) +#define UBSAN_TC_HEAD(a, b) ATF_TC_HEAD(a, b) +#define UBSAN_TC_BODY(a, b) ATF_TC_BODY(a, b) +#define UBSAN_CASES(a) ATF_TP_ADD_TCS(a) +#define