From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751583AbdH3K0v (ORCPT ); Wed, 30 Aug 2017 06:26:51 -0400 Received: from mail-wm0-f52.google.com ([74.125.82.52]:38465 "EHLO mail-wm0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751300AbdH3K0u (ORCPT ); Wed, 30 Aug 2017 06:26:50 -0400 X-Google-Smtp-Source: ADKCNb5U7lwapcxT00lPBy6fgoUNKDusq9NpFtg27heCYJHIrDjrajgQhcROKChSZ+GKhzgesWEkkw== From: Michal Nazarewicz To: Joe Stringer , linux-kernel@vger.kernel.org Cc: Ian Abbott , Arnd Bergmann , Kees Cook , Andrew Morton Subject: Re: [PATCH] compiler: Don't perform compiletime_assert with -O0. In-Reply-To: <20170829230114.11662-1-joe@ovn.org> Organization: http://mina86.com/ References: <20170829230114.11662-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:170830:keescook@chromium.org::hrnjxs9EICgEesPU:00000000000000000000000000000000000000001CdY X-Hashcash: 1:20:170830:abbotti@mev.co.uk::ItUYJrbiwuPStHZN:000000000000000000000000000000000000000000000R4c X-Hashcash: 1:20:170830:linux-kernel@vger.kernel.org::AOgoOWHkWU+sNj/q:0000000000000000000000000000000002bF9 X-Hashcash: 1:20:170830:arnd@arndb.de::UPTx0IKsf0P3iYqA:0000369P X-Hashcash: 1:20:170830:joe@ovn.org::qB9uUv5UuDOZLe5g:0000006GTK X-Hashcash: 1:20:170830:akpm@linux-foundation.org::6qjfaVjHHAS2VUv/:000000000000000000000000000000000000CbV1 Date: Wed, 30 Aug 2017 12:26:44 +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 v7UAQwNr030493 On Tue, Aug 29 2017, Joe Stringer wrote: > Recent changes[0] to make use of __compiletime_assert() from > container_of() increased the usage of this macro, allowing developers to > notice type conflicts in usage of container_of() at compile time. > However, the implementation of __compiletime_assert relies on compiler > optimizations to report an error. This means that if a developer uses > "-O0" with any code that performs container_of(), the compiler will > always report an error regardless of whether there is an actual problem > in the code. > > This patch disables compile_time_assert when optimizations are disabled > to allow such code to compile with CFLAGS="-O0". > > 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 > Cc: Ian Abbott > Cc: Arnd Bergmann > Cc: Michal Nazarewicz > Cc: Kees Cook > Cc: Andrew Morton > --- > include/linux/compiler.h | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/include/linux/compiler.h b/include/linux/compiler.h > index eca8ad75e28b..b67e5ec9b810 100644 > --- a/include/linux/compiler.h > +++ b/include/linux/compiler.h > @@ -517,7 +517,8 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s > # define __compiletime_error_fallback(condition) do { } while (0) > #endif > > -#define __compiletime_assert(condition, msg, prefix, suffix) \ > +#ifdef __OPTIMIZE__ > +# define __compiletime_assert(condition, msg, prefix, suffix) \ > do { \ > bool __cond = !(condition); \ > extern void prefix ## suffix(void) __compiletime_error(msg); \ > @@ -525,6 +526,9 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s > prefix ## suffix(); \ > __compiletime_error_fallback(__cond); \ > } while (0) > +#else > +# define __compiletime_assert(condition, msg, prefix, suffix) +# define __compiletime_assert(condition, msg, prefix, suffix) \ + do { } while (0) With that fix, Acked-by: Michal Nazarewicz > +#endif > > #define _compiletime_assert(condition, msg, prefix, suffix) \ > __compiletime_assert(condition, msg, prefix, suffix) -- Best regards ミハウ “𝓶𝓲𝓷𝓪86” ナザレヴイツ «If at first you don’t succeed, give up skydiving»