Received: by 10.223.164.202 with SMTP id h10csp2919497wrb; Tue, 28 Nov 2017 03:33:05 -0800 (PST) X-Google-Smtp-Source: AGs4zMZSA8mX0q30gnirZ12+jPieV2UK0DZuSS/SbHsn9I0QE0wAMU9VcWq/42lgNRnxvEV0lDOV X-Received: by 10.101.80.205 with SMTP id s13mr39998472pgp.68.1511868785269; Tue, 28 Nov 2017 03:33:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511868785; cv=none; d=google.com; s=arc-20160816; b=TYjYyDPz9lNEqKZljfQ1ptoSJrEtGT7OvrbT0JCocloC3pHUICeQ7lqqNC8f8vkb61 Qk0WrUhWa0um78KlJPzsHx92gOmXpiIRTjRQN9K7Mf4X+FGAaRFuW+ynDgYHQ+pDkggP VSxzs57egqIZm39oOjCpms68/ySt451S0KUOjvoen3tN/P4Q5k9rF1nXCoKvjxpkQ2xJ zI81Kf1XLHuGiKqTN+PdHwa1A6tzkmohc+EPkRnf7tObD7UxTBmE6UkxusoRJnu+gw4S /moHPIjKUeJ4AMDWhQFgCED0nlHs3IgRr9OzMTFaOMeCFkHN7mk4vyOXY15K3SfrJK2c jncA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date :arc-authentication-results; bh=pDA+akfdstY+IcdRqOmamCzqPVmjNqgrQSSp7w352xQ=; b=grtVwOniQ1RIGzH/DcM0fqVIOXiyKOl022NZ0QmxNRRbObhpHmxKODajuEc3dctRhv BoyI/hCGdMCJYspyFfndULCWuVs+U/Is2N1/xOHKtlK8TDQLap4Gk6J3aPx5izIK/fBO WrdUnDRNiYrSYFTsegRx7Sj4aHHEgdk0d/I+zZs1h3FY1ZMIsFGpAZ51KxvCNy35fD+d WfId2xcdixEVB8rSI1KjnRLlwAIOGWDVr8SgP0attoZ30B2J9W8Or0UOIHPn2LoQLdF7 OaAyyjxZ8AunkJoUB9VfKj4UFcE2OQf0BSBqvokEm3DPodfMQrTLCNDKbnAcxFMD16ft 3UQg== ARC-Authentication-Results: i=1; mx.google.com; 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 i191si24086077pge.391.2017.11.28.03.32.53; Tue, 28 Nov 2017 03:33:05 -0800 (PST) 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; 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 S1755109AbdK1Lad (ORCPT + 78 others); Tue, 28 Nov 2017 06:30:33 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:51698 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752722AbdK1Laa (ORCPT ); Tue, 28 Nov 2017 06:30:30 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 91AB71529; Tue, 28 Nov 2017 03:30:30 -0800 (PST) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5EA263F24A; Tue, 28 Nov 2017 03:30:29 -0800 (PST) Date: Tue, 28 Nov 2017 11:30:23 +0000 From: Mark Rutland To: Li Zhijian Cc: acme@redhat.com, linux-kernel@vger.kernel.org, philip.li@intel.com, paulmck@linux.vnet.ibm.com, mingo@kernel.org Subject: Re: [PATCH] tools include: define READ_ONCE/WRITE_ONCE for C++ Message-ID: <20171128113023.43bxgqfflawrlnih@lakrids.cambridge.arm.com> References: <1511849622-3683-1-git-send-email-lizhijian@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1511849622-3683-1-git-send-email-lizhijian@cn.fujitsu.com> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, [Fixed acme's address and added more Ccs] On Tue, Nov 28, 2017 at 02:13:42PM +0800, Li Zhijian wrote: > since 6aa7de0, we failed to build perf with C++(clang) > to fix the following compile errors Sorry about this. With llvm-config and libclang from the LLVM 5.0.0 release, I can reproduce this. > -------------- > 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 So IIUC, g++ doesn't like the union aliasing trick that we use here, and doesn't believe that __val has been initialised. I haven't found a way around that yet. Ideally we'd just have a non-const temporary (and a __builtin_memcpy) rather than a union, but I can't find a way to strip const from typeof() prior to c++11. > ... > -------------- > > 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 This is somewhat unfortunate, since we want to get rid of ACCESS_ONCE(). I'll see if I can come up with something to make the existing {READ,WRITE}_ONCE() work, so that we can avoid issues with non-scalar types. Otherwise, could we please make these: #define READ_ONCE(x) (*(volatile typeof(x) *)&(x)) #define WRITE_ONCE(x) (*(volatile typeof(x) *)&(x)) = (val) Thanks, Mark. > /* > @@ -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 > -- > 2.7.4 > From 1585289467202223313@xxx Tue Nov 28 06:17:28 +0000 2017 X-GM-THRID: 1585289320077919715 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread