From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932766AbbJNNPN (ORCPT ); Wed, 14 Oct 2015 09:15:13 -0400 Received: from terminus.zytor.com ([198.137.202.10]:58824 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932203AbbJNNPI (ORCPT ); Wed, 14 Oct 2015 09:15:08 -0400 Date: Wed, 14 Oct 2015 06:14:46 -0700 From: tip-bot for Jiri Olsa Message-ID: Cc: linux-kernel@vger.kernel.org, acme@redhat.com, hpa@zytor.com, jolsa@kernel.org, rabin@rab.in, mliska@suse.cz, jolsa@redhat.com, a.p.zijlstra@chello.nl, vlee@twopensource.com, tglx@linutronix.de, adrian.hunter@intel.com, mingo@kernel.org, ak@linux.intel.com Reply-To: ak@linux.intel.com, mingo@kernel.org, adrian.hunter@intel.com, tglx@linutronix.de, vlee@twopensource.com, a.p.zijlstra@chello.nl, jolsa@redhat.com, mliska@suse.cz, jolsa@kernel.org, rabin@rab.in, hpa@zytor.com, acme@redhat.com, linux-kernel@vger.kernel.org In-Reply-To: <20151013085214.GB2705@krava.brq.redhat.com> References: <20151013085214.GB2705@krava.brq.redhat.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] tools include: Fix strict-aliasing rules breakage Git-Commit-ID: c95f3432118c6b7a3bde63aa6eb95ccd163119eb X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: c95f3432118c6b7a3bde63aa6eb95ccd163119eb Gitweb: http://git.kernel.org/tip/c95f3432118c6b7a3bde63aa6eb95ccd163119eb Author: Jiri Olsa AuthorDate: Tue, 13 Oct 2015 10:52:14 +0200 Committer: Arnaldo Carvalho de Melo CommitDate: Tue, 13 Oct 2015 11:43:16 -0300 tools include: Fix strict-aliasing rules breakage Vinson reported build breakage with gcc 4.4 due to strict-aliasing. CC util/annotate.o cc1: warnings being treated as errors util/annotate.c: In function ‘disasm__purge’: linux-next/tools/include/linux/compiler.h:66: error: dereferencing pointer ‘res.41’ does break strict-aliasing rules The reason is READ_ONCE/WRITE_ONCE code we took from kernel sources. They intentionaly break aliasing rules. While this is ok for kernel because it's built with -fno-strict-aliasing, it breaks perf which is build with -Wstrict-aliasing=3. Using extra __may_alias__ type to allow aliasing in this case. Reported-and-tested-by: Vinson Lee Signed-off-by: Jiri Olsa Cc: Adrian Hunter Cc: Andi Kleen Cc: Martin Liska Cc: Peter Zijlstra Cc: Rabin Vincent Cc: linux-next@vger.kernel.org Link: http://lkml.kernel.org/r/20151013085214.GB2705@krava.brq.redhat.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/include/linux/compiler.h | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h index 9098083..fa7208a 100644 --- a/tools/include/linux/compiler.h +++ b/tools/include/linux/compiler.h @@ -43,13 +43,29 @@ #include +/* + * Following functions are taken from kernel sources and + * break aliasing rules in their original form. + * + * While kernel is compiled with -fno-strict-aliasing, + * perf uses -Wstrict-aliasing=3 which makes build fail + * under gcc 4.4. + * + * Using extra __may_alias__ type to allow aliasing + * in this case. + */ +typedef __u8 __attribute__((__may_alias__)) __u8_alias_t; +typedef __u16 __attribute__((__may_alias__)) __u16_alias_t; +typedef __u32 __attribute__((__may_alias__)) __u32_alias_t; +typedef __u64 __attribute__((__may_alias__)) __u64_alias_t; + static __always_inline void __read_once_size(const volatile void *p, void *res, int size) { switch (size) { - case 1: *(__u8 *)res = *(volatile __u8 *)p; break; - case 2: *(__u16 *)res = *(volatile __u16 *)p; break; - case 4: *(__u32 *)res = *(volatile __u32 *)p; break; - case 8: *(__u64 *)res = *(volatile __u64 *)p; break; + case 1: *(__u8_alias_t *) res = *(volatile __u8_alias_t *) p; break; + case 2: *(__u16_alias_t *) res = *(volatile __u16_alias_t *) p; break; + case 4: *(__u32_alias_t *) res = *(volatile __u32_alias_t *) p; break; + case 8: *(__u64_alias_t *) res = *(volatile __u64_alias_t *) p; break; default: barrier(); __builtin_memcpy((void *)res, (const void *)p, size); @@ -60,10 +76,10 @@ static __always_inline void __read_once_size(const volatile void *p, void *res, static __always_inline void __write_once_size(volatile void *p, void *res, int size) { switch (size) { - case 1: *(volatile __u8 *)p = *(__u8 *)res; break; - case 2: *(volatile __u16 *)p = *(__u16 *)res; break; - case 4: *(volatile __u32 *)p = *(__u32 *)res; break; - case 8: *(volatile __u64 *)p = *(__u64 *)res; break; + case 1: *(volatile __u8_alias_t *) p = *(__u8_alias_t *) res; break; + case 2: *(volatile __u16_alias_t *) p = *(__u16_alias_t *) res; break; + case 4: *(volatile __u32_alias_t *) p = *(__u32_alias_t *) res; break; + case 8: *(volatile __u64_alias_t *) p = *(__u64_alias_t *) res; break; default: barrier(); __builtin_memcpy((void *)p, (const void *)res, size);