From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751482AbdK1GQR (ORCPT ); Tue, 28 Nov 2017 01:16:17 -0500 Received: from mail.cn.fujitsu.com ([183.91.158.132]:3170 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751041AbdK1GQQ (ORCPT ); Tue, 28 Nov 2017 01:16:16 -0500 X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="30505905" Subject: Re: [PATCH] tools include: define READ_ONCE/WRITE_ONCE for C++ To: CC: , , References: <1511849622-3683-1-git-send-email-lizhijian@cn.fujitsu.com> From: Li Zhijian Message-ID: Date: Tue, 28 Nov 2017 14:16:07 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <1511849622-3683-1-git-send-email-lizhijian@cn.fujitsu.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Originating-IP: [10.167.226.45] X-yoursite-MailScanner-ID: 52444489C476.AAED9 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: lizhijian@cn.fujitsu.com Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org add Arnaldo Carvalho de Melo On 11/28/2017 02:13 PM, Li Zhijian wrote: > since 6aa7de0, we failed to build perf with C++(clang) > to fix the following compile errors > -------------- > lizhijian@haswell-OptiPlex-9020:~/lkp/linux/tools/perf$ make LLVM_CONFIG=/usr/bin/llvm-config-3.9 LIBCLANGLLVM=1 > ... > CC util/probe-finder.o > In file included from /home/lizj/linux/tools/perf/util/util.h:13:0, > from /home/lizj/linux/tools/perf/util/util-cxx.h:20, > from util/c++/clang-c.h:5, > from util/c++/clang-test.cpp:2: > /home/lizj/linux/tools/include/asm/../../arch/x86/include/asm/atomic.h: In function ‘int atomic_read(const atomic_t*)’: > /home/lizj/linux/tools/include/linux/compiler.h:157:45: error: use of deleted function ‘atomic_read(const atomic_t*)::::()’ > ({ union { typeof(x) __val; char __c[1]; } __u; __read_once_size(&(x), __u.__c, sizeof(x)); __u.__val; }) > ^ > /home/lizj/linux/tools/include/asm/../../arch/x86/include/asm/atomic.h:28:9: note: in expansion of macro ‘READ_ONCE’ > return READ_ONCE((v)->counter); > ^ > /home/lizj/linux/tools/include/linux/compiler.h:157:11: note: ‘atomic_read(const atomic_t*)::::()’ is implicitly deleted because the default definition would be ill-formed: > ({ union { typeof(x) __val; char __c[1]; } __u; __read_once_size(&(x), __u.__c, sizeof(x)); __u.__val; }) > ^ > /home/lizj/linux/tools/include/asm/../../arch/x86/include/asm/atomic.h:28:9: note: in expansion of macro ‘READ_ONCE’ > return READ_ONCE((v)->counter); > ^ > /home/lizj/linux/tools/include/linux/compiler.h:157:11: error: uninitialized const member in ‘union atomic_read(const atomic_t*)::’ > ({ union { typeof(x) __val; char __c[1]; } __u; __read_once_size(&(x), __u.__c, sizeof(x)); __u.__val; }) > ^ > /home/lizj/linux/tools/include/asm/../../arch/x86/include/asm/atomic.h:28:9: note: in expansion of macro ‘READ_ONCE’ > return READ_ONCE((v)->counter); > ^ > /home/lizj/linux/tools/include/linux/compiler.h:157:23: note: ‘const int atomic_read(const atomic_t*)::::__val’ should be initialized > ({ union { typeof(x) __val; char __c[1]; } __u; __read_once_size(&(x), __u.__c, sizeof(x)); __u.__val; }) > ^ > /home/lizj/linux/tools/include/asm/../../arch/x86/include/asm/atomic.h:28:9: note: in expansion of macro ‘READ_ONCE’ > return READ_ONCE((v)->counter); > ^ > LD tests/perf-in.o > ... > -------------- > > Signed-off-by: Li Zhijian > --- > tools/include/linux/compiler.h | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h > index 07fd03c..e4c8a0d 100644 > --- a/tools/include/linux/compiler.h > +++ b/tools/include/linux/compiler.h > @@ -86,6 +86,10 @@ > > #define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x)) > > +#ifdef __cplusplus > +#define READ_ONCE(x) ACCESS_ONCE(x) > +#define WRITE_ONCE(x, val) ACCESS_ONCE(x) = val > +#else > #include > > /* > @@ -160,6 +164,7 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s > #define WRITE_ONCE(x, val) \ > ({ union { typeof(x) __val; char __c[1]; } __u = { .__val = (val) }; __write_once_size(&(x), __u.__c, sizeof(x)); __u.__val; }) > > +#endif /* __cplusplus */ > > #ifndef __fallthrough > # define __fallthrough