mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [RFC] perf tools: Fix strict alias issue for find_first_bit
@ 2014-02-26 17:14 Jiri Olsa
  2014-02-26 17:18 ` Peter Zijlstra
  2014-03-02  8:57 ` [tip:perf/urgent] perf tools: Fix strict alias issue for find_first_bit tip-bot for Jiri Olsa
  0 siblings, 2 replies; 4+ messages in thread
From: Jiri Olsa @ 2014-02-26 17:14 UTC (permalink / raw)
  To: linux-kernel
  Cc: Jiri Olsa, Corey Ashford, Frederic Weisbecker, Ingo Molnar,
	Namhyung Kim, Paul Mackerras, Peter Zijlstra,
	Arnaldo Carvalho de Melo, David Ahern

hi,
got issue below when compiling perf tool on i686 with gcc 4.4,
but not sure the patch is correct workaround here.

thanks for comments,
jirka


---
When compiling perf tool code with gcc 4.4.7 I'm getting
following error:

  CC       util/session.o
cc1: warnings being treated as errors
util/session.c: In function ‘perf_session_deliver_event’:
/root/linux/tools/perf/util/include/linux/bitops.h:109: error: dereferencing pointer ‘p’ does break strict-aliasing rules
/root/linux/tools/perf/util/include/linux/bitops.h:101: error: dereferencing pointer ‘p’ does break strict-aliasing rules
util/session.c:697: note: initialized from here
/root/linux/tools/perf/util/include/linux/bitops.h:101: note: initialized from here
make[1]: *** [util/session.o] Error 1
make: *** [util/session.o] Error 2

The aliased types here are u64 and unsigned long pointers,
which is safe for the find_first_bit processing.

This error shows up for me only for gcc 4.4 on 32bit x86,
even for -Wstrict-aliasing=3, while newer gcc are quiet
and scream here for -Wstrict-aliasing={2,1}. Looks like
newer gcc changed the rules for strict alias warnings.

The gcc documentation offers workaround for valid
aliasing by using __may_alias__ attribute:
  http://gcc.gnu.org/onlinedocs/gcc-4.4.0/gcc/Type-Attributes.html

Using this workaround for the find_first_bit function.

Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Cc: David Ahern <dsahern@gmail.com>
---
 tools/perf/util/include/linux/bitops.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/include/linux/bitops.h b/tools/perf/util/include/linux/bitops.h
index 45cf10a..dadfa7e 100644
--- a/tools/perf/util/include/linux/bitops.h
+++ b/tools/perf/util/include/linux/bitops.h
@@ -87,13 +87,15 @@ static __always_inline unsigned long __ffs(unsigned long word)
 	return num;
 }
 
+typedef const unsigned long __attribute__((__may_alias__)) long_alias_t;
+
 /*
  * Find the first set bit in a memory region.
  */
 static inline unsigned long
 find_first_bit(const unsigned long *addr, unsigned long size)
 {
-	const unsigned long *p = addr;
+	long_alias_t *p = (long_alias_t *) addr;
 	unsigned long result = 0;
 	unsigned long tmp;
 
-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-03-02  8:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-26 17:14 [RFC] perf tools: Fix strict alias issue for find_first_bit Jiri Olsa
2014-02-26 17:18 ` Peter Zijlstra
2014-02-26 17:47   ` [PATCH] perf tools: Do not compile with -fstrict-aliasing Jiri Olsa
2014-03-02  8:57 ` [tip:perf/urgent] perf tools: Fix strict alias issue for find_first_bit tip-bot for Jiri Olsa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome