Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3071851imu; Mon, 19 Nov 2018 10:11:30 -0800 (PST) X-Google-Smtp-Source: AJdET5efbCJLQ3N4thbQVoR6veR1izass4UrpTmhWxCdHvE23nnk5ft+wOveHgF16cXlRLk3DnIn X-Received: by 2002:a17:902:8ec2:: with SMTP id x2-v6mr23598292plo.157.1542651090566; Mon, 19 Nov 2018 10:11:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542651090; cv=none; d=google.com; s=arc-20160816; b=X3t3X0SsDZJQFDI+4Dpnf0xKcjwFkoNozYxbHqSEfzwzp3WywsZvXrNA7eA9rj1Xm6 T1sEHDsgbKN56VU1hs9dX9QNIEPAZXzl+rIEuU276c3CS42Jr0+te/NGKGoGauM5LkH8 G3BVL3tidp56nzj6P5XIjR9eIJYJAdwM505EHr6bIMiZOnPZ0HwVuEe9Hb3kUzMwMYhh r270j0+TPiT7WpZBpmGNy1a4M8uykeVWjxbDFKz1+xnupYi2QtPrwT5Z0L2n/zHXsuYz nXj32sVPDs8vlQFV+M54Qc1QhOrATtky25FhvC1ypq7ismQIUPPIttglCj7uw0CnGzVz EaoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=H024FE/5R9+1RH7pcrH8o1llU5cGRF6cB+BVGsKl9OY=; b=sZEyljL3zvH6RMgMJVZ482GSQtaDEwg2mJuA+eLpRb34oLEWro2XgPKES0bNP3sSaD rWVxLCNfvaXVUcWVmHoE8UokNNMxyFnj5NT3//kKh7bevvgsMgqBPhyMl5OYXTrm4Fdx BbGJR5nQkKiCX6k/l367q6iB9sNoy3OTOuwN/EV/y2/1ah9rHZnPKfIz3RlvUNxDgriT YdqnUVI1CQI0aDBpBAJPw7DlqYi0chwBRTKsZWWlET4jO2LRSnhpAUegBVdOpEZi9Def bPlXSf+2e+Ex5sX/C1IfCwjq2DHqPNbY/XZIsBhgkiXC/Nj1U4mB0vq42TVtMOLEm0uP Bdgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=sx78368e; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 2si4370821pgj.104.2018.11.19.10.11.14; Mon, 19 Nov 2018 10:11:30 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=sx78368e; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730347AbeKTEfR (ORCPT + 99 others); Mon, 19 Nov 2018 23:35:17 -0500 Received: from mail-pl1-f194.google.com ([209.85.214.194]:39458 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729975AbeKTEfQ (ORCPT ); Mon, 19 Nov 2018 23:35:16 -0500 Received: by mail-pl1-f194.google.com with SMTP id b5-v6so14959653pla.6 for ; Mon, 19 Nov 2018 10:10:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=H024FE/5R9+1RH7pcrH8o1llU5cGRF6cB+BVGsKl9OY=; b=sx78368eV39Y6BKvqtE9gYLRkGdjO7wsxmuLgV7Y0nR3o/A0TFsBQwzgJnQPxbbFXO nPhGzxn6T+BInbBneUn6hko5a/ItNZouC97D1auEtSOjfmf3skrDpLiW0mj+96rf9dg2 7k3VBt2mALoKwTYqkm8VL+LNlshl8GoD12lCapKZidL6C6GHWA61Xm3Kp3WdfuSq0sDr NK36P0i9U/UrgjRV5br+RtlkbKx81eHOLwpohxGjhHfyzobjjQXTvIXo0YA4i/3NDMVh OHlFzeFySQsCtuYXD2uBB4FG3V/PHIOHS8s2zi+z6gL/58JYlZRhcNo2AjFrsx/ZY3Q0 okCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=H024FE/5R9+1RH7pcrH8o1llU5cGRF6cB+BVGsKl9OY=; b=q5So+U7bAmIQrZIZ0euUnpO0GENOmmh4/mlRLkRKbnDF5KHNszoNh01+RfCczvw5yD 44fBSDyJ3ex83ECTi8ndt//yIlcS+cEwqaO8uA5AN981d8Sl7yqFMhtGLbMDnqncJIg4 vARrrBC0S6sLlwfq8YcUwiLt3pNtpaFO7yAxQ0Yqj6PNVvSzGlw0yDF5+RYLHmOqNH3T j1dlShyo4BRiLlImUU8NfFlRjQOXEmgMSs/KRMOvFxlvPGh/YrT54abLEqNBsTsV2TQO sqIbX8YpsxA+FsrktVamKqpTCSByGz3O05VOuj5NQw6Sn9bYpU5N1mxURDBqv7GHxyiU J6Hw== X-Gm-Message-State: AGRZ1gIusYd8hVrOONo8Quoceb9i96ZEP7Iex5GJU7o1ixud6WeYo4L2 ge039RjKOZUJFmk8oFw2KiYH1h81JVIxK8bH/z3ufA== X-Received: by 2002:a17:902:7b88:: with SMTP id w8mr16290375pll.320.1542651038769; Mon, 19 Nov 2018 10:10:38 -0800 (PST) MIME-Version: 1.0 References: <1542623503-3755-1-git-send-email-yamada.masahiro@socionext.com> <1542623503-3755-2-git-send-email-yamada.masahiro@socionext.com> In-Reply-To: <1542623503-3755-2-git-send-email-yamada.masahiro@socionext.com> From: Nick Desaulniers Date: Mon, 19 Nov 2018 10:10:27 -0800 Message-ID: Subject: Re: [PATCH v3 2/3] build_bug.h: remove negative-array fallback for BUILD_BUG_ON() To: Masahiro Yamada Cc: Andrew Morton , Luc Van Oostenryck , Kees Cook , josh@joshtriplett.org, LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Nov 19, 2018 at 2:32 AM Masahiro Yamada wrote: > > The kernel can only be compiled with an optimization option (-O2, -Os, > or the currently proposed -Og). Hence, __OPTIMIZE__ is always defined > in the kernel source. > > The fallback for the -O0 case is just hypothetical and pointless. > Moreover, commit 0bb95f80a38f ("Makefile: Globally enable VLA warning") > enabled -Wvla warning. The use of variable length arrays is banned. > > Signed-off-by: Masahiro Yamada > Acked-by: Kees Cook > --- > > Changes in v3: None > Changes in v2: None > > include/linux/build_bug.h | 14 -------------- > 1 file changed, 14 deletions(-) > > diff --git a/include/linux/build_bug.h b/include/linux/build_bug.h > index 43d1fd5..d415c64 100644 > --- a/include/linux/build_bug.h > +++ b/include/linux/build_bug.h > @@ -51,23 +51,9 @@ > * If you have some code which relies on certain constants being equal, or > * some other compile-time-evaluated condition, you should use BUILD_BUG_ON to > * detect if someone changes it. > - * > - * The implementation uses gcc's reluctance to create a negative array, but gcc > - * (as of 4.4) only emits that error for obvious cases (e.g. not arguments to > - * inline functions). Luckily, in 4.3 they added the "error" function > - * attribute just for this type of case. Thus, we use a negative sized array > - * (should always create an error on gcc versions older than 4.4) and then call > - * an undefined function with the error attribute (should always create an > - * error on gcc 4.3 and later). If for some reason, neither creates a > - * compile-time error, we'll still have a link-time error, which is harder to > - * track down. > */ > -#ifndef __OPTIMIZE__ > -#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) > -#else > #define BUILD_BUG_ON(condition) \ > BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition) > -#endif > > /** > * BUILD_BUG - break compile if used. > -- > 2.7.4 > Yep seems fine. Reviewed-by: Nick Desaulniers Tested an arm64 defconfig with Clang + this patch. Then tested again with a `BUILD_BUG_ON(4 != 5)` to verify this still breaks the build. Tested-by: Nick Desaulniers -- Thanks, ~Nick Desaulniers