mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-23 23:46:09 +07:00
42466b9f29
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:
f49573d1ee
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.
Fix an issue when HAVE_PERF_REGS_SUPPORT isn't defined from patch v1.
In v3, add perf_regs.c for architectures that HAVE_PERF_REGS_SUPPORT but
don't declare sample_regs_masks.
Further notes:
Jiri asked:
"Is this just a precaution or you actualy saw some breakage?"
Ian answered:
"We saw a breakage with clang with thinlto enabled for linking. Our
compiler team had recently seen, and were surprised by, a similar issue
and were able to dig out the weak ODR issue."
Signed-off-by: Ian Rogers <irogers@google.com>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Albert Ou <aou@eecs.berkeley.edu>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexey Budankov <alexey.budankov@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: clang-built-linux@googlegroups.com
Cc: Guo Ren <guoren@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: linux-riscv@lists.infradead.org
Cc: Mao Han <han_mao@c-sky.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Palmer Dabbelt <palmer@sifive.com>
Cc: Paul Walmsley <paul.walmsley@sifive.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20191001003623.255186-1-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
100 lines
1.9 KiB
C
100 lines
1.9 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include <stdbool.h>
|
|
#include <stdlib.h>
|
|
#include <stdint.h>
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
#include "util/debug.h"
|
|
#include <subcmd/parse-options.h>
|
|
#include "util/perf_regs.h"
|
|
#include "util/parse-regs-options.h"
|
|
|
|
static int
|
|
__parse_regs(const struct option *opt, const char *str, int unset, bool intr)
|
|
{
|
|
uint64_t *mode = (uint64_t *)opt->value;
|
|
const struct sample_reg *r = NULL;
|
|
char *s, *os = NULL, *p;
|
|
int ret = -1;
|
|
uint64_t mask;
|
|
|
|
if (unset)
|
|
return 0;
|
|
|
|
/*
|
|
* cannot set it twice
|
|
*/
|
|
if (*mode)
|
|
return -1;
|
|
|
|
if (intr)
|
|
mask = arch__intr_reg_mask();
|
|
else
|
|
mask = arch__user_reg_mask();
|
|
|
|
/* str may be NULL in case no arg is passed to -I */
|
|
if (str) {
|
|
/* because str is read-only */
|
|
s = os = strdup(str);
|
|
if (!s)
|
|
return -1;
|
|
|
|
for (;;) {
|
|
p = strchr(s, ',');
|
|
if (p)
|
|
*p = '\0';
|
|
|
|
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 || !r->name) {
|
|
ui__warning("Unknown register \"%s\", check man page or run \"perf record %s?\"\n",
|
|
s, intr ? "-I" : "--user-regs=");
|
|
goto error;
|
|
}
|
|
|
|
*mode |= r->mask;
|
|
|
|
if (!p)
|
|
break;
|
|
|
|
s = p + 1;
|
|
}
|
|
}
|
|
ret = 0;
|
|
|
|
/* default to all possible regs */
|
|
if (*mode == 0)
|
|
*mode = mask;
|
|
error:
|
|
free(os);
|
|
return ret;
|
|
}
|
|
|
|
int
|
|
parse_user_regs(const struct option *opt, const char *str, int unset)
|
|
{
|
|
return __parse_regs(opt, str, unset, false);
|
|
}
|
|
|
|
int
|
|
parse_intr_regs(const struct option *opt, const char *str, int unset)
|
|
{
|
|
return __parse_regs(opt, str, unset, true);
|
|
}
|