perf tools: Work around strict aliasing related warnings

Older versions of GCC are rather stupid about strict aliasing:

  util/trace-event-parse.c: In function 'parse_cmdlines':
  util/trace-event-parse.c:93: warning: dereferencing type-punned pointer will break strict-aliasing rules
  util/trace-event-parse.c: In function 'parse_proc_kallsyms':
  util/trace-event-parse.c:155: warning: dereferencing type-punned pointer will break strict-aliasing rules
  util/trace-event-parse.c:157: warning: dereferencing type-punned pointer will break strict-aliasing rules
  util/trace-event-parse.c:158: warning: dereferencing type-punned pointer will break strict-aliasing rules
  util/trace-event-parse.c: In function 'parse_ftrace_printk':
  util/trace-event-parse.c:294: warning: dereferencing type-punned pointer will break strict-aliasing rules
  util/trace-event-parse.c:295: warning: dereferencing type-punned pointer will break strict-aliasing rules
  make: *** [util/trace-event-parse.o] Error 1

Make it clear to GCC that we intend with those pointers, by passing
them through via an explicit (void *) cast.

We might want to add -fno-strict-aliasing as well, like the kernel
itself does.

Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
LKML-Reference: <new-submission>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
This commit is contained in:
Ingo Molnar 2009-09-02 14:55:55 +02:00
parent 61562445c8
commit 65014ab361
2 changed files with 7 additions and 7 deletions

View file

@ -188,7 +188,7 @@ int bigendian(void)
unsigned char str[] = { 0x1, 0x2, 0x3, 0x4, 0x0, 0x0, 0x0, 0x0};
unsigned int *ptr;
ptr = (unsigned int *)str;
ptr = (unsigned int *)(void *)str;
return *ptr == 0x01020304;
}

View file

@ -90,7 +90,7 @@ void parse_cmdlines(char *file, int size __unused)
while (line) {
item = malloc_or_die(sizeof(*item));
sscanf(line, "%d %as", &item->pid,
(float *)&item->comm); /* workaround gcc warning */
(float *)(void *)&item->comm); /* workaround gcc warning */
item->next = list;
list = item;
line = strtok_r(NULL, "\n", &next);
@ -152,10 +152,10 @@ void parse_proc_kallsyms(char *file, unsigned int size __unused)
item = malloc_or_die(sizeof(*item));
item->mod = NULL;
ret = sscanf(line, "%as %c %as\t[%as",
(float *)&addr_str, /* workaround gcc warning */
(float *)(void *)&addr_str, /* workaround gcc warning */
&ch,
(float *)&item->func,
(float *)&item->mod);
(float *)(void *)&item->func,
(float *)(void *)&item->mod);
item->addr = strtoull(addr_str, NULL, 16);
free(addr_str);
@ -291,8 +291,8 @@ void parse_ftrace_printk(char *file, unsigned int size __unused)
while (line) {
item = malloc_or_die(sizeof(*item));
ret = sscanf(line, "%as : %as",
(float *)&addr_str, /* workaround gcc warning */
(float *)&item->printk);
(float *)(void *)&addr_str, /* workaround gcc warning */
(float *)(void *)&item->printk);
item->addr = strtoull(addr_str, NULL, 16);
free(addr_str);