perf annotate-data: Add stack canary type

When the stack protector is enabled, compiler would generate code to
check stack overflow with a special value called 'stack carary' at
runtime.  On x86_64, GCC hard-codes the stack canary as %gs:40.

While there's a definition of fixed_percpu_data in asm/processor.h,
it seems that the header is not included everywhere and many places
it cannot find the type info.  As it's in the well-known location (at
%gs:40), let's add a pseudo stack canary type to handle it specially.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: https://lore.kernel.org/r/20240319055115.4063940-22-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Namhyung Kim
2024-03-18 22:51:13 -07:00
committed by Arnaldo Carvalho de Melo
parent eb9190afae
commit b3c95109c1
3 changed files with 72 additions and 0 deletions

View File

@@ -118,6 +118,13 @@ struct annotated_data_type stackop_type = {
},
};
struct annotated_data_type canary_type = {
.self = {
.type_name = (char *)"(stack canary)",
.children = LIST_HEAD_INIT(canary_type.self.children),
},
};
static int arch__grow_instructions(struct arch *arch)
{
struct ins *new_instructions;
@@ -3803,6 +3810,18 @@ static bool is_stack_operation(struct arch *arch, struct disasm_line *dl)
return false;
}
static bool is_stack_canary(struct arch *arch, struct annotated_op_loc *loc)
{
/* On x86_64, %gs:40 is used for stack canary */
if (arch__is(arch, "x86")) {
if (loc->segment == INSN_SEG_X86_GS && loc->imm &&
loc->offset == 40)
return true;
}
return false;
}
u64 annotate_calc_pcrel(struct map_symbol *ms, u64 ip, int offset,
struct disasm_line *dl)
{
@@ -3929,6 +3948,12 @@ retry:
}
mem_type = find_data_type(&dloc);
if (mem_type == NULL && is_stack_canary(arch, op_loc)) {
mem_type = &canary_type;
dloc.type_offset = 0;
}
if (mem_type)
istat->good++;
else