From patchwork Tue Dec 8 23:59:14 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 7802871 Return-Path: X-Original-To: patchwork-linux-kbuild@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 99C4E9F1C2 for ; Tue, 8 Dec 2015 23:59:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C4CC120450 for ; Tue, 8 Dec 2015 23:59:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DAFD320434 for ; Tue, 8 Dec 2015 23:59:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751967AbbLHX7R (ORCPT ); Tue, 8 Dec 2015 18:59:17 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:42848 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751033AbbLHX7Q (ORCPT ); Tue, 8 Dec 2015 18:59:16 -0500 Received: from akpm3.mtv.corp.google.com (unknown [216.239.45.65]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 2BC68C5F; Tue, 8 Dec 2015 23:59:15 +0000 (UTC) Date: Tue, 8 Dec 2015 15:59:14 -0800 From: Andrew Morton To: Andrey Ryabinin Cc: , Peter Zijlstra , Sasha Levin , Randy Dunlap , Rasmus Villemoes , Jonathan Corbet , Michal Marek , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Yury Gribov , Dmitry Vyukov , Konstantin Khlebnikov , Kostya Serebryany , , , Subject: Re: [PATCH v4 3/3] UBSAN: run-time undefined behavior sanity checker Message-Id: <20151208155914.d0b005c82906f3203660fd47@linux-foundation.org> In-Reply-To: <1449157807-20298-4-git-send-email-aryabinin@virtuozzo.com> References: <1449157807-20298-1-git-send-email-aryabinin@virtuozzo.com> <1449157807-20298-4-git-send-email-aryabinin@virtuozzo.com> X-Mailer: Sylpheed 3.4.1 (GTK+ 2.24.23; x86_64-pc-linux-gnu) Mime-Version: 1.0 Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Thu, 3 Dec 2015 18:50:07 +0300 Andrey Ryabinin wrote: > UBSAN uses compile-time instrumentation to catch undefined behavior (UB). > Compiler inserts code that perform certain kinds of checks before > operations that could cause UB. If check fails (i.e. UB detected) > __ubsan_handle_* function called to print error message. > > So the most of the work is done by compiler. This patch just > implements ubsan handlers printing errors. > > GCC has this capability since 4.9.x [1] (see -fsanitize=undefined > option and its suboptions). > However GCC 5.x has more checkers implemented [2]. > Article [3] has a bit more details about UBSAN in the GCC. > > ... > > +#ifdef CONFIG_ARCH_SUPPORTS_INT128 > +typedef __int128 s_max; > +typedef unsigned __int128 u_max; > +#else In file included from lib/ubsan.c:21: lib/ubsan.h:77: error: expected '=', ',', ';', 'asm' or '__attribute__' before 's_max' lib/ubsan.h:78: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'u_max' lib/ubsan.c:89: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'get_signed_val' gcc-4.4.4 doesn't appear to like __int128. The only other use of __int128 is include/linux/math64.h:mul_u64_u32_shr() and it uses defined(__SIZEOF_INT128__) as well. Using that gives me lib/ubsan.c: In function 'val_to_string': lib/ubsan.c:127: warning: right shift count >= width of type lib/ubsan.c:128: warning: right shift count >= width of type so I bodged that site too. I need to get an mmotm release out the door. --- a/lib/ubsan.c~ubsan-run-time-undefined-behavior-sanity-checker-fix-3 +++ a/lib/ubsan.c @@ -120,7 +120,7 @@ static void val_to_string(char *str, siz { if (type_is_int(type)) { if (type_bit_width(type) == 128) { -#ifdef CONFIG_ARCH_SUPPORTS_INT128 +#if defined(CONFIG_ARCH_SUPPORTS_INT128) && defined(__SIZEOF_INT128__) u_max val = get_unsigned_val(type, value); scnprintf(str, size, "0x%08x%08x%08x%08x", --- a/lib/ubsan.h~ubsan-run-time-undefined-behavior-sanity-checker-fix-3 +++ a/lib/ubsan.h @@ -73,7 +73,7 @@ struct invalid_value_data { struct type_descriptor *type; }; -#ifdef CONFIG_ARCH_SUPPORTS_INT128 +#if defined(CONFIG_ARCH_SUPPORTS_INT128) && defined(__SIZEOF_INT128__) typedef __int128 s_max; typedef unsigned __int128 u_max; #else