Commit 92730852 authored by Ian Rogers's avatar Ian Rogers Committed by Arnaldo Carvalho de Melo
Browse files

perf disasm: Rework the string arch__is to use the ELF machine



Add new arch__is_x86 and arch__is_powerpc functions that avoid string
comparisons and use the ELF machine.

Remove arch__is() that is no longer used.

Reviewed-by: default avatarJames Clark <james.clark@linaro.org>
Signed-off-by: default avatarIan Rogers <irogers@google.com>
Cc: Aditya Bodkhe <aditya.b1@linux.ibm.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Albert Ou <aou@eecs.berkeley.edu>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexandre Ghiti <alex@ghiti.fr>
Cc: Athira Rajeev <atrajeev@linux.ibm.com>
Cc: Bill Wendling <morbo@google.com>
Cc: Dr. David Alan Gilbert <linux@treblig.org>
Cc: Guo Ren <guoren@kernel.org>
Cc: Howard Chu <howardchu95@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Julia Lawall <Julia.Lawall@inria.fr>
Cc: Justin Stitt <justinstitt@google.com>
Cc: Krzysztof Łopatowski <krzysztof.m.lopatowski@gmail.com>
Cc: Leo Yan <leo.yan@linux.dev>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Nick Desaulniers <nick.desaulniers+lkml@gmail.com>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Paul Walmsley <pjw@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Sergei Trofimovich <slyich@gmail.com>
Cc: Shimin Guo <shimin.guo@skydio.com>
Cc: Suchit Karunakaran <suchitkarunakaran@gmail.com>
Cc: Thomas Falcon <thomas.falcon@intel.com>
Cc: Tianyou Li <tianyou.li@intel.com>
Cc: Will Deacon <will@kernel.org>
Cc: Zecheng Li <zecheng@google.com>
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 2a1ca20d
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -165,7 +165,7 @@ static void init_type_state(struct type_state *state, const struct arch *arch)
	memset(state, 0, sizeof(*state));
	INIT_LIST_HEAD(&state->stack_vars);

	if (arch__is(arch, "x86")) {
	if (arch__is_x86(arch)) {
		state->regs[0].caller_saved = true;
		state->regs[1].caller_saved = true;
		state->regs[2].caller_saved = true;
@@ -526,7 +526,7 @@ static enum type_match_result check_variable(struct data_loc_info *dloc,
		needs_pointer = false;
	else if (reg == dloc->fbreg || is_fbreg)
		needs_pointer = false;
	else if (arch__is(dloc->arch, "x86") && reg == X86_REG_SP)
	else if (arch__is_x86(dloc->arch) && reg == X86_REG_SP)
		needs_pointer = false;

	/* Get the type of the variable */
@@ -1071,7 +1071,7 @@ static void delete_var_types(struct die_var_type *var_types)
/* should match to is_stack_canary() in util/annotate.c */
static void setup_stack_canary(struct data_loc_info *dloc)
{
	if (arch__is(dloc->arch, "x86")) {
	if (arch__is_x86(dloc->arch)) {
		dloc->op->segment = INSN_SEG_X86_GS;
		dloc->op->imm = true;
		dloc->op->offset = 40;
@@ -1311,7 +1311,7 @@ static enum type_match_result check_matching_type(struct type_state *state,

		/* Direct this-cpu access like "%gs:0x34740" */
		if (dloc->op->segment == INSN_SEG_X86_GS && dloc->op->imm &&
		    arch__is(dloc->arch, "x86")) {
		    arch__is_x86(dloc->arch)) {
			pr_debug_dtp("this-cpu var");

			addr = dloc->op->offset;
@@ -1397,7 +1397,7 @@ static enum type_match_result find_data_type_insn(struct data_loc_info *dloc,

static int arch_supports_insn_tracking(struct data_loc_info *dloc)
{
	if ((arch__is(dloc->arch, "x86")) || (arch__is(dloc->arch, "powerpc")))
	if ((arch__is_x86(dloc->arch)) || (arch__is_powerpc(dloc->arch)))
		return 1;
	return 0;
}
+8 −8
Original line number Diff line number Diff line
@@ -2474,7 +2474,7 @@ static int extract_reg_offset(const struct arch *arch, const char *str,
	 * %gs:0x18(%rbx).  In that case it should skip the part.
	 */
	if (*str == arch->objdump.register_char) {
		if (arch__is(arch, "x86")) {
		if (arch__is_x86(arch)) {
			/* FIXME: Handle other segment registers */
			if (!strncmp(str, "%gs:", 4))
				op_loc->segment = INSN_SEG_X86_GS;
@@ -2571,7 +2571,7 @@ int annotate_get_insn_location(const struct arch *arch, struct disasm_line *dl,
		op_loc->reg2 = -1;

		if (insn_str == NULL) {
			if (!arch__is(arch, "powerpc"))
			if (!arch__is_powerpc(arch))
				continue;
		}

@@ -2580,7 +2580,7 @@ int annotate_get_insn_location(const struct arch *arch, struct disasm_line *dl,
		 * required fields for op_loc, ie reg1, reg2, offset from the
		 * raw instruction.
		 */
		if (arch__is(arch, "powerpc")) {
		if (arch__is_powerpc(arch)) {
			op_loc->mem_ref = mem_ref;
			op_loc->multi_regs = multi_regs;
			get_powerpc_regs(dl->raw.raw_insn, !i, op_loc);
@@ -2591,7 +2591,7 @@ int annotate_get_insn_location(const struct arch *arch, struct disasm_line *dl,
		} else {
			char *s, *p = NULL;

			if (arch__is(arch, "x86")) {
			if (arch__is_x86(arch)) {
				/* FIXME: Handle other segment registers */
				if (!strncmp(insn_str, "%gs:", 4)) {
					op_loc->segment = INSN_SEG_X86_GS;
@@ -2675,7 +2675,7 @@ static struct annotated_item_stat *annotate_data_stat(struct list_head *head,

static bool is_stack_operation(const struct arch *arch, struct disasm_line *dl)
{
	if (arch__is(arch, "x86")) {
	if (arch__is_x86(arch)) {
		if (!strncmp(dl->ins.name, "push", 4) ||
		    !strncmp(dl->ins.name, "pop", 3) ||
		    !strncmp(dl->ins.name, "call", 4) ||
@@ -2689,7 +2689,7 @@ static bool is_stack_operation(const struct arch *arch, struct disasm_line *dl)
static bool is_stack_canary(const struct arch *arch, struct annotated_op_loc *loc)
{
	/* On x86_64, %gs:40 is used for stack canary */
	if (arch__is(arch, "x86")) {
	if (arch__is_x86(arch)) {
		if (loc->segment == INSN_SEG_X86_GS && loc->imm &&
		    loc->offset == 40)
			return true;
@@ -2704,7 +2704,7 @@ static bool is_stack_canary(const struct arch *arch, struct annotated_op_loc *lo
 */
static bool is_address_gen_insn(const struct arch *arch, struct disasm_line *dl)
{
	if (arch__is(arch, "x86")) {
	if (arch__is_x86(arch)) {
		if (!strncmp(dl->ins.name, "lea", 3))
			return true;
	}
@@ -2847,7 +2847,7 @@ __hist_entry__get_data_type(struct hist_entry *he, const struct arch *arch,
		}

		/* This CPU access in kernel - pretend PC-relative addressing */
		if (dso__kernel(map__dso(ms->map)) && arch__is(arch, "x86") &&
		if (dso__kernel(map__dso(ms->map)) && arch__is_x86(arch) &&
		    op_loc->segment == INSN_SEG_X86_GS && op_loc->imm) {
			dloc.var_addr = op_loc->offset;
			op_loc->reg1 = DWARF_REG_PC;
+1 −1
Original line number Diff line number Diff line
@@ -147,7 +147,7 @@ static void print_capstone_detail(cs_insn *insn, char *buf, size_t len,
	struct symbol *sym;

	/* TODO: support more architectures */
	if (!arch__is(args->arch, "x86"))
	if (!arch__is_x86(args->arch))
		return;

	if (insn->detail == NULL)
+10 −5
Original line number Diff line number Diff line
@@ -228,9 +228,14 @@ const struct arch *arch__find(const char *name)
	return bsearch(name, architectures, nmemb, sizeof(struct arch), arch__key_cmp);
}

bool arch__is(const struct arch *arch, const char *name)
bool arch__is_x86(const struct arch *arch)
{
	return !strcmp(arch->name, name);
	return arch->e_machine == EM_386 || arch->e_machine == EM_X86_64;
}

bool arch__is_powerpc(const struct arch *arch)
{
	return arch->e_machine == EM_PPC || arch->e_machine == EM_PPC64;
}

static void ins_ops__delete(struct ins_operands *ops)
@@ -877,7 +882,7 @@ static const struct ins_ops *__ins__find(const struct arch *arch, const char *na
	struct ins *ins;
	const int nmemb = arch->nr_instructions;

	if (arch__is(arch, "powerpc")) {
	if (arch__is_powerpc(arch)) {
		/*
		 * For powerpc, identify the instruction ops
		 * from the opcode using raw_insn.
@@ -1066,7 +1071,7 @@ struct disasm_line *disasm_line__new(struct annotate_args *args)
		goto out_delete;

	if (args->offset != -1) {
		if (arch__is(args->arch, "powerpc")) {
		if (arch__is_powerpc(args->arch)) {
			if (disasm_line__parse_powerpc(dl, args) < 0)
				goto out_free_line;
		} else if (disasm_line__parse(dl->al.line, &dl->ins.name, &dl->ops.raw) < 0)
@@ -1700,7 +1705,7 @@ int symbol__disassemble(struct symbol *sym, struct annotate_args *args)
	 * and typeoff, disassemble to mnemonic notation is not required in
	 * case of powerpc.
	 */
	if (arch__is(args->arch, "powerpc")) {
	if (arch__is_powerpc(args->arch)) {
		extern const char *sort_order;

		if (sort_order && !strstr(sort_order, "sym")) {
+2 −1
Original line number Diff line number Diff line
@@ -106,7 +106,8 @@ struct annotate_args {
};

const struct arch *arch__find(const char *name);
bool arch__is(const struct arch *arch, const char *name);
bool arch__is_x86(const struct arch *arch);
bool arch__is_powerpc(const struct arch *arch);

const struct ins_ops *ins__find(const struct arch *arch, const char *name, struct disasm_line *dl);

Loading