All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf tools: avoid sample_reg_masks being const + weak
@ 2019-09-27 21:10 Ian Rogers
  2019-09-27 21:43 ` [PATCH v2] " Ian Rogers
  0 siblings, 1 reply; 19+ messages in thread
From: Ian Rogers @ 2019-09-27 21:10 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Alexander Shishkin, Jiri Olsa, Namhyung Kim, Andi Kleen,
	linux-kernel
  Cc: Stephane Eranian, Ian Rogers

Being const + weak breaks with some compilers that constant-propagate
from the weak symbol. This behavior is outside of the specification, but
in LLVM is chosen to match GCC's behavior.

LLVM's implementation was set in this patch:
https://github.com/llvm/llvm-project/commit/f49573d1eedcf1e44893d5a062ac1b72c8419646
A const + weak symbol is set to be weak_odr:
https://llvm.org/docs/LangRef.html
ODR is one definition rule, and given there is one constant definition
constant-propagation is possible. It is possible to get this code to
miscompile with LLVM when applying link time optimization. As compilers
become more aggressive, this is likely to break in more instances.

Move the definition of sample_reg_masks to the conditional part of
perf_regs.h and guard usage with HAVE_PERF_REGS_SUPPORT. This avoids the
weak symbol.

Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/util/parse-regs-options.c | 4 ++++
 tools/perf/util/perf_regs.c          | 4 ----
 tools/perf/util/perf_regs.h          | 4 ++--
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/tools/perf/util/parse-regs-options.c b/tools/perf/util/parse-regs-options.c
index ef46c2848808..a6a776597df8 100644
--- a/tools/perf/util/parse-regs-options.c
+++ b/tools/perf/util/parse-regs-options.c
@@ -46,18 +46,22 @@ __parse_regs(const struct option *opt, const char *str, int unset, bool intr)
 
 			if (!strcmp(s, "?")) {
 				fprintf(stderr, "available registers: ");
+#ifdef HAVE_PERF_REGS_SUPPORT
 				for (r = sample_reg_masks; r->name; r++) {
 					if (r->mask & mask)
 						fprintf(stderr, "%s ", r->name);
 				}
+#endif
 				fputc('\n', stderr);
 				/* just printing available regs */
 				return -1;
 			}
+#ifdef HAVE_PERF_REGS_SUPPORT
 			for (r = sample_reg_masks; r->name; r++) {
 				if ((r->mask & mask) && !strcasecmp(s, r->name))
 					break;
 			}
+#endif
 			if (!r->name) {
 				ui__warning("Unknown register \"%s\", check man page or run \"perf record %s?\"\n",
 					    s, intr ? "-I" : "--user-regs=");
diff --git a/tools/perf/util/perf_regs.c b/tools/perf/util/perf_regs.c
index 2774cec1f15f..5ee47ae1509c 100644
--- a/tools/perf/util/perf_regs.c
+++ b/tools/perf/util/perf_regs.c
@@ -3,10 +3,6 @@
 #include "perf_regs.h"
 #include "event.h"
 
-const struct sample_reg __weak sample_reg_masks[] = {
-	SMPL_REG_END
-};
-
 int __weak arch_sdt_arg_parse_op(char *old_op __maybe_unused,
 				 char **new_op __maybe_unused)
 {
diff --git a/tools/perf/util/perf_regs.h b/tools/perf/util/perf_regs.h
index 47fe34e5f7d5..e014c2c038f4 100644
--- a/tools/perf/util/perf_regs.h
+++ b/tools/perf/util/perf_regs.h
@@ -15,8 +15,6 @@ struct sample_reg {
 #define SMPL_REG2(n, b) { .name = #n, .mask = 3ULL << (b) }
 #define SMPL_REG_END { .name = NULL }
 
-extern const struct sample_reg sample_reg_masks[];
-
 enum {
 	SDT_ARG_VALID = 0,
 	SDT_ARG_SKIP,
@@ -27,6 +25,8 @@ uint64_t arch__intr_reg_mask(void);
 uint64_t arch__user_reg_mask(void);
 
 #ifdef HAVE_PERF_REGS_SUPPORT
+extern const struct sample_reg sample_reg_masks[];
+
 #include <perf_regs.h>
 
 #define DWARF_MINIMAL_REGS ((1ULL << PERF_REG_IP) | (1ULL << PERF_REG_SP))
-- 
2.23.0.444.g18eeb5a265-goog


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

end of thread, other threads:[~2019-10-16 15:05 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-27 21:10 [PATCH] perf tools: avoid sample_reg_masks being const + weak Ian Rogers
2019-09-27 21:43 ` [PATCH v2] " Ian Rogers
2019-09-29 21:05   ` Jiri Olsa
2019-09-30 10:39     ` Arnaldo Carvalho de Melo
2019-09-30 12:23     ` Arnaldo Carvalho de Melo
2019-09-30 12:42       ` Jiri Olsa
2019-10-01  0:36         ` Ian Rogers
2019-10-01  0:36   ` [PATCH v3] " Ian Rogers
2019-10-01  0:36     ` Ian Rogers
2019-10-07 20:49     ` Nick Desaulniers
2019-10-07 20:49       ` Nick Desaulniers
2019-10-08 12:31     ` Jiri Olsa
2019-10-08 12:31       ` Jiri Olsa
2019-10-09 23:07       ` Ian Rogers
2019-10-09 23:07         ` Ian Rogers
2019-10-10 12:29         ` Arnaldo Carvalho de Melo
2019-10-10 12:29           ` Arnaldo Carvalho de Melo
2019-10-15  5:31     ` [tip: perf/core] perf tools: Avoid 'sample_reg_masks' " tip-bot2 for Ian Rogers
2019-10-15  5:31       ` tip-bot2 for Ian Rogers

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.