diff options
author | Ingo Molnar <mingo@elte.hu> | 2009-08-15 06:26:57 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-08-16 04:47:47 -0400 |
commit | 83a0944fa919fb2ebcfc1f8933d86e437b597ca6 (patch) | |
tree | 814906744656554a1bc07cdad6b84b3581565358 /tools/perf/builtin-annotate.c | |
parent | 6baa0a5ae0954fb2486c480a20556a9f1aee0965 (diff) |
perf: Enable more compiler warnings
Related to a shadowed variable bug fix Valdis Kletnieks noticed
that perf does not get built with -Wshadow, which could have
helped us avoid the bug.
So enable -Wshadow and also enable the following warnings on
perf builds, in addition to the already enabled -Wall -Wextra
-std=gnu99 warnings:
-Wcast-align
-Wformat=2
-Wshadow
-Winit-self
-Wpacked
-Wredundant-decls
-Wstack-protector
-Wstrict-aliasing=3
-Wswitch-default
-Wswitch-enum
-Wno-system-headers
-Wundef
-Wvolatile-register-var
-Wwrite-strings
-Wbad-function-cast
-Wmissing-declarations
-Wmissing-prototypes
-Wnested-externs
-Wold-style-definition
-Wstrict-prototypes
-Wdeclaration-after-statement
And change/fix the perf code to build cleanly under GCC 4.3.2.
The list of warnings enablement is rather arbitrary: it's based
on my (quick) reading of the GCC manpages and trying them on
perf.
I categorized the warnings based on individually enabling them
and looking whether they trigger something in the perf build.
If i liked those warnings (i.e. if they trigger for something
that arguably could be improved) i enabled the warning.
If the warnings seemed to come from language laywers spamming
the build with tons of nuisance warnings i generally kept them
off. Most of the sign conversion related warnings were in
this category. (A second patch enabling some of the sign
warnings might be welcome - sign bugs can be nasty.)
I also kept warnings that seem to make sense from their manpage
description and which produced no actual warnings on our code
base. These warnings might still be turned off if they end up
being a nuisance.
I also left out a few warnings that are not supported in older
compilers.
[ Note that these changes might break the build on older
compilers i did not test, or on non-x86 architectures that
produce different warnings, so more testing would be welcome. ]
Reported-by: Valdis.Kletnieks@vt.edu
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>
Diffstat (limited to 'tools/perf/builtin-annotate.c')
-rw-r--r-- | tools/perf/builtin-annotate.c | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c index 3bedaa5d21d2..32ff9838351e 100644 --- a/tools/perf/builtin-annotate.c +++ b/tools/perf/builtin-annotate.c | |||
@@ -81,7 +81,7 @@ struct hist_entry { | |||
81 | struct sort_entry { | 81 | struct sort_entry { |
82 | struct list_head list; | 82 | struct list_head list; |
83 | 83 | ||
84 | char *header; | 84 | const char *header; |
85 | 85 | ||
86 | int64_t (*cmp)(struct hist_entry *, struct hist_entry *); | 86 | int64_t (*cmp)(struct hist_entry *, struct hist_entry *); |
87 | int64_t (*collapse)(struct hist_entry *, struct hist_entry *); | 87 | int64_t (*collapse)(struct hist_entry *, struct hist_entry *); |
@@ -225,7 +225,7 @@ static struct sort_entry sort_sym = { | |||
225 | static int sort__need_collapse = 0; | 225 | static int sort__need_collapse = 0; |
226 | 226 | ||
227 | struct sort_dimension { | 227 | struct sort_dimension { |
228 | char *name; | 228 | const char *name; |
229 | struct sort_entry *entry; | 229 | struct sort_entry *entry; |
230 | int taken; | 230 | int taken; |
231 | }; | 231 | }; |
@@ -723,7 +723,7 @@ parse_line(FILE *file, struct symbol *sym, u64 start, u64 len) | |||
723 | const char *path = NULL; | 723 | const char *path = NULL; |
724 | unsigned int hits = 0; | 724 | unsigned int hits = 0; |
725 | double percent = 0.0; | 725 | double percent = 0.0; |
726 | char *color; | 726 | const char *color; |
727 | struct sym_ext *sym_ext = sym->priv; | 727 | struct sym_ext *sym_ext = sym->priv; |
728 | 728 | ||
729 | offset = line_ip - start; | 729 | offset = line_ip - start; |
@@ -805,7 +805,7 @@ static void free_source_line(struct symbol *sym, int len) | |||
805 | 805 | ||
806 | /* Get the filename:line for the colored entries */ | 806 | /* Get the filename:line for the colored entries */ |
807 | static void | 807 | static void |
808 | get_source_line(struct symbol *sym, u64 start, int len, char *filename) | 808 | get_source_line(struct symbol *sym, u64 start, int len, const char *filename) |
809 | { | 809 | { |
810 | int i; | 810 | int i; |
811 | char cmd[PATH_MAX * 2]; | 811 | char cmd[PATH_MAX * 2]; |
@@ -851,7 +851,7 @@ get_source_line(struct symbol *sym, u64 start, int len, char *filename) | |||
851 | } | 851 | } |
852 | } | 852 | } |
853 | 853 | ||
854 | static void print_summary(char *filename) | 854 | static void print_summary(const char *filename) |
855 | { | 855 | { |
856 | struct sym_ext *sym_ext; | 856 | struct sym_ext *sym_ext; |
857 | struct rb_node *node; | 857 | struct rb_node *node; |
@@ -867,7 +867,7 @@ static void print_summary(char *filename) | |||
867 | node = rb_first(&root_sym_ext); | 867 | node = rb_first(&root_sym_ext); |
868 | while (node) { | 868 | while (node) { |
869 | double percent; | 869 | double percent; |
870 | char *color; | 870 | const char *color; |
871 | char *path; | 871 | char *path; |
872 | 872 | ||
873 | sym_ext = rb_entry(node, struct sym_ext, node); | 873 | sym_ext = rb_entry(node, struct sym_ext, node); |
@@ -882,7 +882,7 @@ static void print_summary(char *filename) | |||
882 | 882 | ||
883 | static void annotate_sym(struct dso *dso, struct symbol *sym) | 883 | static void annotate_sym(struct dso *dso, struct symbol *sym) |
884 | { | 884 | { |
885 | char *filename = dso->name, *d_filename; | 885 | const char *filename = dso->name, *d_filename; |
886 | u64 start, end, len; | 886 | u64 start, end, len; |
887 | char command[PATH_MAX*2]; | 887 | char command[PATH_MAX*2]; |
888 | FILE *file; | 888 | FILE *file; |
@@ -892,7 +892,7 @@ static void annotate_sym(struct dso *dso, struct symbol *sym) | |||
892 | if (sym->module) | 892 | if (sym->module) |
893 | filename = sym->module->path; | 893 | filename = sym->module->path; |
894 | else if (dso == kernel_dso) | 894 | else if (dso == kernel_dso) |
895 | filename = vmlinux; | 895 | filename = vmlinux_name; |
896 | 896 | ||
897 | start = sym->obj_start; | 897 | start = sym->obj_start; |
898 | if (!start) | 898 | if (!start) |
@@ -964,7 +964,7 @@ static int __cmd_annotate(void) | |||
964 | int ret, rc = EXIT_FAILURE; | 964 | int ret, rc = EXIT_FAILURE; |
965 | unsigned long offset = 0; | 965 | unsigned long offset = 0; |
966 | unsigned long head = 0; | 966 | unsigned long head = 0; |
967 | struct stat stat; | 967 | struct stat input_stat; |
968 | event_t *event; | 968 | event_t *event; |
969 | uint32_t size; | 969 | uint32_t size; |
970 | char *buf; | 970 | char *buf; |
@@ -977,13 +977,13 @@ static int __cmd_annotate(void) | |||
977 | exit(-1); | 977 | exit(-1); |
978 | } | 978 | } |
979 | 979 | ||
980 | ret = fstat(input, &stat); | 980 | ret = fstat(input, &input_stat); |
981 | if (ret < 0) { | 981 | if (ret < 0) { |
982 | perror("failed to stat file"); | 982 | perror("failed to stat file"); |
983 | exit(-1); | 983 | exit(-1); |
984 | } | 984 | } |
985 | 985 | ||
986 | if (!stat.st_size) { | 986 | if (!input_stat.st_size) { |
987 | fprintf(stderr, "zero-sized file, nothing to do!\n"); | 987 | fprintf(stderr, "zero-sized file, nothing to do!\n"); |
988 | exit(0); | 988 | exit(0); |
989 | } | 989 | } |
@@ -1010,10 +1010,10 @@ more: | |||
1010 | 1010 | ||
1011 | if (head + event->header.size >= page_size * mmap_window) { | 1011 | if (head + event->header.size >= page_size * mmap_window) { |
1012 | unsigned long shift = page_size * (head / page_size); | 1012 | unsigned long shift = page_size * (head / page_size); |
1013 | int ret; | 1013 | int munmap_ret; |
1014 | 1014 | ||
1015 | ret = munmap(buf, page_size * mmap_window); | 1015 | munmap_ret = munmap(buf, page_size * mmap_window); |
1016 | assert(ret == 0); | 1016 | assert(munmap_ret == 0); |
1017 | 1017 | ||
1018 | offset += shift; | 1018 | offset += shift; |
1019 | head -= shift; | 1019 | head -= shift; |
@@ -1049,7 +1049,7 @@ more: | |||
1049 | 1049 | ||
1050 | head += size; | 1050 | head += size; |
1051 | 1051 | ||
1052 | if (offset + head < (unsigned long)stat.st_size) | 1052 | if (offset + head < (unsigned long)input_stat.st_size) |
1053 | goto more; | 1053 | goto more; |
1054 | 1054 | ||
1055 | rc = EXIT_SUCCESS; | 1055 | rc = EXIT_SUCCESS; |
@@ -1092,7 +1092,7 @@ static const struct option options[] = { | |||
1092 | "be more verbose (show symbol address, etc)"), | 1092 | "be more verbose (show symbol address, etc)"), |
1093 | OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, | 1093 | OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, |
1094 | "dump raw trace in ASCII"), | 1094 | "dump raw trace in ASCII"), |
1095 | OPT_STRING('k', "vmlinux", &vmlinux, "file", "vmlinux pathname"), | 1095 | OPT_STRING('k', "vmlinux", &vmlinux_name, "file", "vmlinux pathname"), |
1096 | OPT_BOOLEAN('m', "modules", &modules, | 1096 | OPT_BOOLEAN('m', "modules", &modules, |
1097 | "load module symbols - WARNING: use only with -k and LIVE kernel"), | 1097 | "load module symbols - WARNING: use only with -k and LIVE kernel"), |
1098 | OPT_BOOLEAN('l', "print-line", &print_line, | 1098 | OPT_BOOLEAN('l', "print-line", &print_line, |