Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp4202157imm; Sat, 25 Aug 2018 11:19:07 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYp6e/3yB3t7lJMCryT3atYz1cBF9hJdYjPU4r4iCvBzs+9oH4v69C6hM7HnJknLHXtxE8z X-Received: by 2002:a17:902:7b83:: with SMTP id w3-v6mr6552884pll.192.1535221147835; Sat, 25 Aug 2018 11:19:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535221147; cv=none; d=google.com; s=arc-20160816; b=nFlLdhJYrZg28B0rOWENJwISyJAB0tO0/SVAEqD+Wo4lgpjoYh16sxCBzu7AowxaFD iy0OZWt0tb+V2b5CcVPHpP3n5qjUux8WMUcLHF3TC9Hz62gwfUSzMVYThgOx4tzckWPW VzfkSZhhQMLy8yCpH/1r+KpPolS4NBSL9XPdPTLqNJ2Uw8D6uP7Qt6j0MrvfvNTU7mjC 74xs+5qvqkMSlSauqBMKHGSqkVRXHlP+oajmlp7fs5qoG7nT5Y8Pc3q+mwrgxYHmYEj6 z2puvOq67/wQEnX3dIrafgM/R8+TaeRdtubMzyVR2x+rpf6jQYyvBpUldLaTrVUQhPR9 LDeg== 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 t191-v6si9559553pgc.481.2018.08.25.11.18.51; Sat, 25 Aug 2018 11:19:07 -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 S1726969AbeHYV4v (ORCPT + 99 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(-) 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) -- 2.7.4