mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git
synced 2026-11-09 19:10:45 +01:00
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. 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 <[email protected]> Reviewed-by: Nick Desaulniers <[email protected]> Acked-by: Jiri Olsa <[email protected]> Cc: Albert Ou <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Alexey Budankov <[email protected]> Cc: Andi Kleen <[email protected]> Cc: [email protected] Cc: Guo Ren <[email protected]> Cc: Kan Liang <[email protected]> Cc: [email protected] Cc: Mao Han <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Palmer Dabbelt <[email protected]> Cc: Paul Walmsley <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Stephane Eranian <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
47 lines
800 B
C
47 lines
800 B
C
// SPDX-License-Identifier: GPL-2.0
|
|
#include <errno.h>
|
|
#include "perf_regs.h"
|
|
#include "event.h"
|
|
|
|
int __weak arch_sdt_arg_parse_op(char *old_op __maybe_unused,
|
|
char **new_op __maybe_unused)
|
|
{
|
|
return SDT_ARG_SKIP;
|
|
}
|
|
|
|
uint64_t __weak arch__intr_reg_mask(void)
|
|
{
|
|
return PERF_REGS_MASK;
|
|
}
|
|
|
|
uint64_t __weak arch__user_reg_mask(void)
|
|
{
|
|
return PERF_REGS_MASK;
|
|
}
|
|
|
|
#ifdef HAVE_PERF_REGS_SUPPORT
|
|
int perf_reg_value(u64 *valp, struct regs_dump *regs, int id)
|
|
{
|
|
int i, idx = 0;
|
|
u64 mask = regs->mask;
|
|
|
|
if (regs->cache_mask & (1ULL << id))
|
|
goto out;
|
|
|
|
if (!(mask & (1ULL << id)))
|
|
return -EINVAL;
|
|
|
|
for (i = 0; i < id; i++) {
|
|
if (mask & (1ULL << i))
|
|
idx++;
|
|
}
|
|
|
|
regs->cache_mask |= (1ULL << id);
|
|
regs->cache_regs[id] = regs->regs[idx];
|
|
|
|
out:
|
|
*valp = regs->cache_regs[id];
|
|
return 0;
|
|
}
|
|
#endif
|