Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf dwarf-aux: Use signed variable types in match_var_offset

match_var_offset() compares address offsets to determine if an access
falls within a variable's bounds. The offsets involved for those
relative to base registers from DW_OP_breg can be negative.

The current implementation uses unsigned types (u64) for these offsets,
which rejects almost all negative values.

Change the signature of match_var_offset() to use signed types (s64).

This ensures correct behavior when addr_offset or addr_type are
negative.

Reviewed-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Zecheng Li <zecheng@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Xu Liu <xliuprof@google.com>
Link: https://lore.kernel.org/r/20250825195412.223077-2-zecheng@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Zecheng Li and committed by
Arnaldo Carvalho de Melo
414bf79d 9105df01

+6 -5
+6 -5
tools/perf/util/dwarf-aux.c
··· 1388 1388 #define DWARF_OP_DIRECT_REGS 32 1389 1389 1390 1390 static bool match_var_offset(Dwarf_Die *die_mem, struct find_var_data *data, 1391 - u64 addr_offset, u64 addr_type, bool is_pointer) 1391 + s64 addr_offset, s64 addr_type, bool is_pointer) 1392 1392 { 1393 1393 Dwarf_Die type_die; 1394 1394 Dwarf_Word size; 1395 + s64 offset = addr_offset - addr_type; 1395 1396 1396 - if (addr_offset == addr_type) { 1397 + if (offset == 0) { 1397 1398 /* Update offset relative to the start of the variable */ 1398 1399 data->offset = 0; 1399 1400 return true; 1400 1401 } 1401 1402 1402 - if (addr_offset < addr_type) 1403 + if (offset < 0) 1403 1404 return false; 1404 1405 1405 1406 if (die_get_real_type(die_mem, &type_die) == NULL) ··· 1415 1414 if (dwarf_aggregate_size(&type_die, &size) < 0) 1416 1415 return false; 1417 1416 1418 - if (addr_offset >= addr_type + size) 1417 + if ((u64)offset >= size) 1419 1418 return false; 1420 1419 1421 1420 /* Update offset relative to the start of the variable */ 1422 - data->offset = addr_offset - addr_type; 1421 + data->offset = offset; 1423 1422 return true; 1424 1423 } 1425 1424