Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756306AbdHYLpd (ORCPT ); Fri, 25 Aug 2017 07:45:33 -0400 Received: from mail-wr0-f178.google.com ([209.85.128.178]:34669 "EHLO mail-wr0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755173AbdHYLpb (ORCPT ); Fri, 25 Aug 2017 07:45:31 -0400 X-Google-Smtp-Source: ADKCNb421d2l3spdHNQbe0E+CLQZ8XWCY91kAFrLjJijJ/ouKDfoQjborcpsVNxMHKoZ4AINLFIa6g== From: Michal Nazarewicz To: Joe Stringer , linux-kernel@vger.kernel.org Cc: Ian Abbott , Arnd Bergmann , Kees Cook Subject: Re: [PATCH net-next] compiler: Document behavior compiling with -O0 In-Reply-To: <20170824164506.9108-1-joe@ovn.org> Organization: http://mina86.com/ References: <20170824164506.9108-1-joe@ovn.org> Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAJFBMVEWbfGlUPDDHgE57V0jUupKjgIObY0PLrom9mH4dFRK4gmjPs41MxjOgAAACP0lEQVQ4T23Sv2vbQBQHcBk1xE6WyALX107VUEgmn6+ouUwpEQQ6uRjttkWP4CkBg2M0BQLBdPFZYPsyFYo7qEtKDQ7on+t7+nF2Ux8ahD587717OmNYrOvycHsZ+o2r051wHTHysAvGb8ygvgu4QWT0sCmkgZCIEnlV2X8BtyraazFGDuxhmKSQJMlwHQ7v5MHSNxmz78rfElwAa3ieVD9e+hBhjaPDDG6NgFo2f4wBMNIo5YmRtF0RyDgFjJjlMIWbnuM4x9MMfABGTlN4qgIQB4A1DEyA1BHWtfeWNUMwiVJKoqh97KrkOO+qzgluVYLvFCUKAX73nONeBr7BGMdM6Sg0kuep03VywLaIzRiVr+GAzKlpQIsAFnWAG2e6DT5WmWDiudZMIc6hYrMOmeMQK9WX0B+/RfjzL9DI7Y9/Iayn29Ci0r2i4f9gMimMSZLCDMalgQGU5hnUtqAN0OGvEmO1Wnl0C0wWSCEHnuHBqmygxdxA8oWXwbipoc1EoNR9DqOpBpOJrnr0criQab9ZT4LL+wI+K7GBQH30CrhUruilgP9DRTrhVWZCiAyILP+wiuLeCKGTD6r/nc8LOJcAwR6IBTUs+7CASw3QFZ0MdA2PI3zNziH4ZKVhXCRMBjeZ1DWMekKwDCASwExy+NQ86TaykaDAFHO4aP48y4fIcDM5yOG8GcTLbOyp8A8azjJI93JFd1EA6yN8sSxMQJWoABqniRZVykYgRXErzrdqExAoUrRb0xfRp8p2A/4XmfilTtkDZ4cAAAAASUVORK5CYII= X-Face: -TR8(rDTHy/(xl?SfWd1|3:TTgDIatE^t'vop%*gVg[kn$t{EpK(P"VQ=~T2#ysNmJKN$"yTRLB4YQs$4{[.]Fc1)*O]3+XO^oXM>Q#b^ix,O)Zbn)q[y06$`e3?C)`CwR9y5riE=fv^X@x$y?D:XO6L&x4f-}}I4=VRNwiA^t1-ZrVK^07.Pi/57c_du'& OpenPGP: id=AC1F5F5CD41888F8CC8458582060401250751FF4; url=http://mina86.com/mina86.pub X-Hashcash: 1:20:170825:keescook@chromium.org::I3vStk5R0SGMo561:00000000000000000000000000000000000000000rEK X-Hashcash: 1:20:170825:arnd@arndb.de::fzQ1rFpVKzvUv3Zc:00000ELy X-Hashcash: 1:20:170825:joe@ovn.org::4Oj9k6OncT3mznrh:0000009OsN X-Hashcash: 1:20:170825:abbotti@mev.co.uk::d1odEuUpn1tP7/VW:000000000000000000000000000000000000000000006qdz X-Hashcash: 1:20:170825:linux-kernel@vger.kernel.org::hZ1ShXhfcDOpjjz/:0000000000000000000000000000000007fIg Date: Fri, 25 Aug 2017 13:45:28 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by nfs id v7PBjdjg021148 Content-Length: 2993 Lines: 67 On Thu, Aug 24 2017, Joe Stringer wrote: > Recent changes[0] to make use of __compiletime_assert() from container_of() > increased the scope of this macro, resulting in a wider set of > situations where developers cannot compile their code using "-O0". I > noticed this when making use of the macro in my own development, and > spent more time than I'd like to admit tracking the problem down. This > patch documents the behavior in lieu of a compile-time assertion > implementation that does not rely on optimizations. > > Example compilation failure: > > ./include/linux/compiler.h:547:38: error: call to ‘__compiletime_assert_94’ declared with attribute error: pointer type mismatch in container_of() > _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__) > ^ > ./include/linux/compiler.h:530:4: note: in definition of macro ‘__compiletime_assert’ > prefix ## suffix(); \ > ^~~~~~ > ./include/linux/compiler.h:547:2: note: in expansion of macro ‘_compiletime_assert’ > _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__) > ^~~~~~~~~~~~~~~~~~~ > ./include/linux/build_bug.h:46:37: note: in expansion of macro ‘compiletime_assert’ > #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg) > ^~~~~~~~~~~~~~~~~~ > ./include/linux/kernel.h:860:2: note: in expansion of macro ‘BUILD_BUG_ON_MSG’ > BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) && \ > ^~~~~~~~~~~~~~~~ > > [0] http://lkml.kernel.org/r/20170525120316.24473-7-abbotti@mev.co.uk > > Signed-off-by: Joe Stringer > --- > include/linux/compiler.h | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/include/linux/compiler.h b/include/linux/compiler.h > index eca8ad75e28b..bb640167fdac 100644 > --- a/include/linux/compiler.h > +++ b/include/linux/compiler.h > @@ -517,6 +517,11 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s > # define __compiletime_error_fallback(condition) do { } while (0) > #endif > > +/* > + * __compiletime_assert() relies on compiler optimizations to remove the check > + * against '__cond' if 'condition' is false. As a result, compiling with -O0 > + * will cause compilation errors here regardless of the value of 'condition'. > + */ > #define __compiletime_assert(condition, msg, prefix, suffix) \ > do { \ > bool __cond = !(condition); \ Could __builtin_choose_expr help here? Something like: #define __compiletime_assert(condition, msg, prefix, suffix) \ do { \ bool __cond = !(condition); \ extern int prefix ## suffix(void) __compiletime_error(msg); \ __builting_choose_expr(cond, prefix ## suffix(), 0); \ __compiletime_error_fallback(__cond); \ } while (0) Or better still, _Static_assert? -- Best regards ミハウ “????????????????86” ナザレヴイツ «If at first you don’t succeed, give up skydiving»