From patchwork Sun Aug 19 05:51:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 144522 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2580229ljj; Sat, 18 Aug 2018 22:53:29 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxsRVu9AgjE8P4X5+DJKq2hinHdzda+NbfciFSLMBfmfaKkY77LqZWwcatVsLIIAjUKstUn X-Received: by 2002:a17:902:aa83:: with SMTP id d3-v6mr40001233plr.242.1534658009407; Sat, 18 Aug 2018 22:53:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534658009; cv=none; d=google.com; s=arc-20160816; b=d1jVArmqDGRKG4OmomE+ntVxsSLbcz+NtjC3WBmDUUTM3U3otbFviFhBUbT5ln5Mtm 2fyhYOOcBy1XagW+wLAn93klMRwSHT0BiJoKoEvCB0PelFbISJ8NXvFM/B6S5MBW7l9O V8ISWnfjrJOEBf/9zc1jtF1gCu9Zp86dnEGkY2RcmvI7UHhlohIdAPIDxpLKsmq9ZNJj ch9xbmNl015jIBP0jdMm4j/IwiOFsAhSIRAlLco9JVQMlKnb6l1+uBMxRZ2hFEZfiQrt IfG8OPfav2XX4a+uF5JlyHGR7L183aT94QGdT9yQRyl3Bf+nIRvIjwSyWYn1DT/luSIc 1sLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter:arc-authentication-results; bh=AJ5o3WeTaVzWN4TQSQZ+BAvlJAeuRtOAc3TzW++J5QQ=; b=RWB48+CyHBg61QV52Sxak006pEFhsyEzOOUSm65jE9F8TGtghFyy1ZeYYi6005uvyD FTq7N8XTUlUGImw03Fnvil8o6tfiXBIJaWX5GD1gZxe09OmSpLnuuWjuhb6TXmMBrTdU ONKYajYacdGuSE7O2z3JGI9E6AJHRE0Mky/BeimJMBO3jPQdQC6iOYURGKuQxjYisI2K 59/SfOROeAx+6lHJW/Ck8PmnTFwbv7SZb6O6GsxrPjhSyewspz22tdrwm7oSKwNtklh2 Xfy9MexdGOpYr1el1R5ZWhlY2NSAOQKJz/2/Y8OmS0zqFJj/PjKXveroH4mLFpF0BA+S K4Ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=cRXrtkty; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x1-v6si6545423plv.26.2018.08.18.22.53.28; Sat, 18 Aug 2018 22:53:29 -0700 (PDT) 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=@nifty.com header.s=dec2015msa header.b=cRXrtkty; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726116AbeHSJDj (ORCPT + 32 others); Sun, 19 Aug 2018 05:03:39 -0400 Received: from conuserg-12.nifty.com ([210.131.2.79]:49329 "EHLO conuserg-12.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725929AbeHSJDj (ORCPT ); Sun, 19 Aug 2018 05:03:39 -0400 Received: from grover.tkatk1.zaq.ne.jp (zaqdadce369.zaq.ne.jp [218.220.227.105]) (authenticated) by conuserg-12.nifty.com with ESMTP id w7J5q2sB006201; Sun, 19 Aug 2018 14:52:02 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-12.nifty.com w7J5q2sB006201 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1534657923; bh=AJ5o3WeTaVzWN4TQSQZ+BAvlJAeuRtOAc3TzW++J5QQ=; h=From:To:Cc:Subject:Date:From; b=cRXrtkty1TuaFQvg/sQGTBjxYaz+nW5j4dOXUy6tRe1hUQ4F4/U+RaHJ33tSRjsAW 9+eD9Oj/RW2W1yGcJvTERrJ1KfiQDjz36LRlEZBj5zRaXrhB4DkWASnfuUM2gzqCbf NhKzXAmYAhM9eHepPLb5R5YCmNZEfSlN+y1s2yX1So06PTzM+c1wgQRY2nzWal5Hmx DESNQoXT0CkhYb4FL7xRLdXPxchrOknvY3XrMirT6SGe8APJElJYHhMSrHuVx2Djtu Mx6+EZeYpwgCgPndrWr6kHiE3zscWU7p30tKiVynTNUSW8kqhzeR764tl7BY32fqeC /plbn6pSMwalA== X-Nifty-SrcIP: [218.220.227.105] From: Masahiro Yamada To: Andrew Morton , Linus Torvalds Cc: James Hogan , Joe Stringer , Daniel Santos , Rusty Russell , Arnd Bergmann , Kees Cook , Masahiro Yamada , Christopher Li , linux-sparse@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH] compiler.h: give up __compiletime_assert_fallback() Date: Sun, 19 Aug 2018 14:51:20 +0900 Message-Id: <1534657880-11573-1-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org __compiletime_assert_fallback() is supposed to stop building earlier by using the negative-array-size method in case the compiler does not support "error" attribute, but has never worked like that. You can try this simple code: #include void foo(void) { BUILD_BUG_ON(1); } GCC (precisely, GCC 4.3 or later) immediately terminates the build, but Clang does not report anything because Clang does not support the "error" attribute now. It will eventually fail in the link stage, but at least __compiletime_assert_fallback() is not working. The root cause is commit 1d6a0d19c855 ("bug.h: prevent double evaluation of `condition' in BUILD_BUG_ON"). Prior to that commit, BUILD_BUG_ON() was checked by the negative-array-size method *and* the link-time trick. Since that commit, the negative-array-size is not effective because '__cond' is no longer constant. As the comment in says, GCC (and Clang as well) only emits the error for obvious cases. When '__cond' is a variable, ((void)sizeof(char[1 - 2 * __cond])) ... is not obvious for the compiler to know the array size is negative. One way to fix this is to stop the variable assignment, i.e. to pass '!(condition)' directly to __compiletime_error_fallback() at the cost of the double evaluation of 'condition'. However, all calls of BUILD_BUG() would be turned into errors even if they are called from dead-code. This commit does not change the current behavior since it just rips off the code that has not been effective for some years. Signed-off-by: Masahiro Yamada --- include/linux/compiler.h | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) -- 2.7.4 Reviewed-by: Kees Cook Reviewed-by: Nick Desaulniers diff --git a/include/linux/compiler.h b/include/linux/compiler.h index 42506e4..c062238f4 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -295,29 +295,14 @@ unsigned long read_word_at_a_time(const void *addr) #endif #ifndef __compiletime_error # define __compiletime_error(message) -/* - * Sparse complains of variable sized arrays due to the temporary variable in - * __compiletime_assert. Unfortunately we can't just expand it out to make - * sparse see a constant array size without breaking compiletime_assert on old - * versions of GCC (e.g. 4.2.4), so hide the array from sparse altogether. - */ -# ifndef __CHECKER__ -# define __compiletime_error_fallback(condition) \ - do { ((void)sizeof(char[1 - 2 * condition])); } while (0) -# endif -#endif -#ifndef __compiletime_error_fallback -# define __compiletime_error_fallback(condition) do { } while (0) #endif #ifdef __OPTIMIZE__ # define __compiletime_assert(condition, msg, prefix, suffix) \ do { \ - bool __cond = !(condition); \ extern void prefix ## suffix(void) __compiletime_error(msg); \ - if (__cond) \ + if (!(condition)) \ prefix ## suffix(); \ - __compiletime_error_fallback(__cond); \ } while (0) #else # define __compiletime_assert(condition, msg, prefix, suffix) do { } while (0)