From patchwork Fri May 31 06:01:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Chancellor X-Patchwork-Id: 165504 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp289050ili; Thu, 30 May 2019 23:04:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqwraYx8i0GkUPu9Klbmc2NA+CZMI0nTBW36d9RSWp1PFVRwfTveYvIuXiZRx5njs35Z2Isc X-Received: by 2002:a62:2b82:: with SMTP id r124mr7697870pfr.235.1559282656000; Thu, 30 May 2019 23:04:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559282655; cv=none; d=google.com; s=arc-20160816; b=0FCQvg9eWVdFKt+qi7xV5Zq+h7qNRDUEXOc1QpMj7JRcCUIXGJg5xHD+2aoqIRoq3U HAOPaCUt7rg2Hub+LkMO6dZV4yDVlu9iVIVJWDCaA/5D+a8WKm0Ymkql7rzhJLB8AeuC afICr45kY0z2DSs8qBLIL4SR4oIqr78tF54YawfY01L2EaWkYpSjaLlx7KCuAXvEmKLP 59B+524ThwhoiICnohVSdHb06n1HuIMeuj/GgnSvb8TSUFF595Gkwb7yvP8/4Zx4uIAL innH9Lv8Rt+t5Dm2G/rMStuDE80/C+n5Bh4AIpzrx5YtZtNuYh3R8rx2Nu18vco4xloj ULHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=xeJtG7vEar5JVvT9PCS2XrltCjozk3OE5Wgh3IZCm48=; b=qbpNOW+1HeJnOknzyk1qzLDf/s/cLlrYPoMSrk1aevxeRTgzAhyRzuyeG/Vt8iFe06 9Jl7YzZPfa+TqITo14bnsTbFlvRem1fl5TUPzXnAhdrp7BHpaLBmtTRSpC7Z1eyOdREa 9/LQ87Vd7UFzfCueBPBX9cepOLvnGD3c2s2Qy5AgA68oIyupNK8zzLTScdR76FwRASm7 +Gx/XkqSxCBr1ST0W5zp4e4MdivBnR0RWA1DFxDFg8YD7sVpddbk77O98KsVYEdFgGpt Ull4b/TcDlLOp/OH+V2M7zZMJK41VxfRKRX8p2GzyaV/RnJvcY0U1IH4orp446eN+53F q1wA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=gZFICE+J; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m2si4875513pgv.89.2019.05.30.23.04.15; Thu, 30 May 2019 23:04:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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=@gmail.com header.s=20161025 header.b=gZFICE+J; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726331AbfEaGEP (ORCPT + 14 others); Fri, 31 May 2019 02:04:15 -0400 Received: from mail-ed1-f68.google.com ([209.85.208.68]:39675 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725955AbfEaGEP (ORCPT ); Fri, 31 May 2019 02:04:15 -0400 Received: by mail-ed1-f68.google.com with SMTP id e24so12792978edq.6 for ; Thu, 30 May 2019 23:04:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=xeJtG7vEar5JVvT9PCS2XrltCjozk3OE5Wgh3IZCm48=; b=gZFICE+J9YJB/dVuG+P4RmSBhGxFlflDNSFVLINZmw0ueczc1xcH45vTifwugcB+yw n8I3S1wJUmDdRAAd9bLFH4FJ4Vg4RwvOSVeB96mRzvAqbk19/UcbqTkYO9QxXOdn8jVS aoBMPREM+MYyWXPvXWjIz+3u4090SuYeWGyHGK4TGFzhmB6xLo3Xl/9HWEexCHhrMr3D sLIsJk5bzYNvkeTjvQR04KzAU4IejV5QpbnKqo/5LTT8y1d6Jih7iGqRu0nY9bNHo9HQ D/lWdcHu6TJ2FRAC+JN0q8EtoLCIKt89jKtlcJt6kRk35zi/n2L8TAh6f4WJ3rMoFE8E aZZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=xeJtG7vEar5JVvT9PCS2XrltCjozk3OE5Wgh3IZCm48=; b=FDWE2TaAHm0fAlSTFQM4OJmSq/cxIHXtzcJrC+KM3LQ7mT3z4SsLLb4eWJau0J1ZeX SXEsG82QzQ2MlkCCtBLVXUIj+AUXlqI2Yi4A76GimC86mTuZNbWJI0Mei9u5MXt0z388 tXa93cFdANshW3vwCDKGQ4mMaxJ6OaM9YQTBfo8NxN7wbnIoOTRcILYN2neuR7mMcTp5 UGgRj73TEIwg8/G0VtGHGodiSyCsq9/xNrg8+A0PmSWcydkSFydRGhOwrCMg3IC1S7La YGUXv5IB5O3n88mZIkK3tK6hwS0u16OLuga1oyaoS7TdOf3xvpC5y+gtBWiwCKkMWwvX viyw== X-Gm-Message-State: APjAAAXIG9WfgrFhBS1KXq3PHAaCo3rGP/cfNtYfY25DNIiruqemuxuj 1GkXRKIPHvM7V4Mx1B39rtg= X-Received: by 2002:a50:f286:: with SMTP id f6mr6677791edm.44.1559282653176; Thu, 30 May 2019 23:04:13 -0700 (PDT) Received: from localhost.localdomain ([2a01:4f9:2b:2b15::2]) by smtp.gmail.com with ESMTPSA id g18sm1314552edh.13.2019.05.30.23.04.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 May 2019 23:04:12 -0700 (PDT) From: Nathan Chancellor To: Greg Kroah-Hartman , Sasha Levin Cc: stable@vger.kernel.org, clang-built-linux@googlegroups.com, Masahiro Yamada , Kees Cook , Nick Desaulniers , Nathan Chancellor Subject: [PATCH 4.19] compiler.h: give up __compiletime_assert_fallback() Date: Thu, 30 May 2019 23:01:10 -0700 Message-Id: <20190531060109.124476-1-natechancellor@gmail.com> X-Mailer: git-send-email 2.22.0.rc2 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Masahiro Yamada commit 81b45683487a51b0f4d3b29d37f20d6d078544e4 upstream. __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 Signed-off-by: Kees Cook Signed-off-by: Nathan Chancellor --- Hi Greg and Sasha, Please pick up this patch for 4.19. It fixes an insane amount of spam from the drivers/gpu/drm/i915 subsystem because they enable the -Wvla warning and we have been carrying it in our CI for a while. include/linux/compiler.h | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) -- 2.22.0.rc2 diff --git a/include/linux/compiler.h b/include/linux/compiler.h index 81c2238b884c..bb22908c79e8 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -319,29 +319,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)