From patchwork Sat Aug 25 18:16:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 145126 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp2513114ljw; Sat, 25 Aug 2018 11:17:13 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYL8zzQr6M4qqKvSvsRsV0XeDagqN0wcTwgTGuJ/Lusexwv1/T65Q8uDIrY075GTWUJgVoO X-Received: by 2002:a17:902:8481:: with SMTP id c1-v6mr6537997plo.177.1535221032960; Sat, 25 Aug 2018 11:17:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535221032; cv=none; d=google.com; s=arc-20160816; b=qfVTrfLA5S69+xRqBvDEtBnooVG6zq/ki5x0Zww+tRhk1Wwd4URqaw/6Ohwsu9TkyK UBmROVlO2R3lQHPjy0NmO+VRf1uIB3/ih+vkAy7rR3yWx+mY92igqeSOyxuSs9GQAyDh 4XVsmYdFYlgrYpaiVrDZKCaVdOIMxdjWTcGU6i/P+886eupoM12V2rqrZKkrYJJVM+cy e/2CvaCNbZzBu1GenWigk6cExX+8CKGF/wpmxHzRBsh2jhMZigVwULQ5Qyk+MtCCIABh C1MMDrg4+kl8CkEPtHFINpL/db6OlHDl4PocOVUfUyKoKvXmkjYVTNw98JeF+JDbEsTI 36tA== 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=j+K7PHGyJBhSYAiDGKYPS2wMpUuPPd1zgTSqpkO6vBE=; b=mRGssGc+G4fQ85/A1Tz0VdNzAUh5nOSZ/ZD8tNgmSzVESq2Bv2Ubgspy69PhbB8Ejt EVyoEpCRkf12e2HwVIlvNx4wcNg8XuMYCdunde35dSFNQKo8SWuAF6CqcWtXaqGSOzK1 o5+zhODNBEZEWjsKpVLl6DTb4Nborcmd6Qb6+O85tE9sPR5ozd/WOwJFVppCt+iHc3Ay 3BLrDoV0SdWosS8aa4afc2SXVnx0UT440j2wsR3U6lSdMvfcn4RRhkTsBmuSC/FvYgLC td/YLUYEYHyH4bOXUASME1Ta/ZgqQVTH/MA2C9dL6rPXnbbxZ0Bom9q0WvSWLdp2wgZ8 +dhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b="yN/JvsaW"; 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 m126-v6si11265063pfb.126.2018.08.25.11.17.12; Sat, 25 Aug 2018 11:17:12 -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="yN/JvsaW"; 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 S1727043AbeHYV4v (ORCPT + 32 others); Sat, 25 Aug 2018 17:56:51 -0400 Received: from conuserg-09.nifty.com ([210.131.2.76]:60229 "EHLO conuserg-09.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726854AbeHYV4v (ORCPT ); Sat, 25 Aug 2018 17:56:51 -0400 Received: from grover.tkatk1.zaq.ne.jp (zaqdadce369.zaq.ne.jp [218.220.227.105]) (authenticated) by conuserg-09.nifty.com with ESMTP id w7PIGZeW027987; Sun, 26 Aug 2018 03:16:35 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com w7PIGZeW027987 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1535220995; bh=j+K7PHGyJBhSYAiDGKYPS2wMpUuPPd1zgTSqpkO6vBE=; h=From:To:Cc:Subject:Date:From; b=yN/JvsaWv7RTaBYJjmESTHH49Pvpr4dMIbUJqvz7UCf4GDE6UMkvEy0dmd44ulrkt 7WO7dXbkcb7OrsXHyoypVy7gB+71cd3GzPI023QNPkabwhfNq9yJYsJE9XYHkQJHLs NiKODu+THPqLlUaL9FnaaYMZJ03Ml5JgD/0Sbi9A5lqFzGTzpokO7HhFJ7q5G2VgOT SkM21vUACqMNLZThjy+3ufH/3sUO3lf2mHytCODeqQCFdMbDhDeeaksVzlDF4PCnix kGnKxkYRt1U8mC9lUMQVL6KqzJG1CP/1V1GB0IE1mx/5Go73EMdsnJdUsnCoLwBBmx ENOZTUGHbyrKQ== X-Nifty-SrcIP: [218.220.227.105] From: Masahiro Yamada To: Linus Torvalds Cc: Kees Cook , Nick Desaulniers , Daniel Santos , Masahiro Yamada , Christopher Li , linux-sparse@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] compiler.h: give up __compiletime_assert_fallback() Date: Sun, 26 Aug 2018 03:16:29 +0900 Message-Id: <1535220989-27645-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 simply try: BUILD_BUG_ON(1); GCC immediately terminates the build, but Clang does not report anything because Clang does not support the "error" attribute now. It will later fail at link time, but __compiletime_assert_fallback() is not working at least. 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. Reverting that commit would break BUILD_BUG() because negative-size-array is evaluated before the code is optimized out. Let's give up __compiletime_assert_fallback(). This commit does not change the current behavior since it just rips off the useless code. Signed-off-by: Masahiro Yamada Reviewed-by: Kees Cook Reviewed-by: Nick Desaulniers --- Changes in v2: - Rebase include/linux/compiler.h | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) -- 2.7.4 diff --git a/include/linux/compiler.h b/include/linux/compiler.h index 681d866..87c776c 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -314,29 +314,14 @@ static inline void *offset_to_ptr(const int *off) #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 { \ - int __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)