Commit [b39c2a]  Maximize  Restore  History

perf tools: Fix strict alias issue for find_first_bit

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’:
tools/perf/util/include/linux/bitops.h:109: error: dereferencing pointer ‘p’ does break strict-aliasing rules
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
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:

Using this workaround for the find_first_bit function.

Signed-off-by: Jiri Olsa <>
Cc: Corey Ashford <>
Cc: David Ahern <>
Cc: Frederic Weisbecker <>
Cc: Ingo Molnar <>
Cc: Namhyung Kim <>
Cc: Paul Mackerras <>
Cc: Peter Zijlstra <>
Signed-off-by: Arnaldo Carvalho de Melo <>

Jiri Olsa Jiri Olsa 2014-02-26

Arnaldo Carvalho de Melo Arnaldo Carvalho de Melo 2014-02-28

changed tools/perf/util/include/linux/bitops.h
tools/perf/util/include/linux/bitops.h Diff Switch to side-by-side view

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks