mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Sathvika Vasireddy <sv@linux.ibm.com>
Cc: linuxppc-dev@lists.ozlabs.org, jpoimboe@redhat.com,
	linux-kernel@vger.kernel.org, aik@ozlabs.ru, mpe@ellerman.id.au,
	rostedt@goodmis.org, naveen.n.rao@linux.vnet.ibm.com
Subject: Re: [RFC PATCH 3/3] objtool/mcount: Add powerpc specific functions
Date: Fri, 18 Mar 2022 13:26:56 +0100	[thread overview]
Message-ID: <YjR6kHq4c/rjCTpr@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20220318105140.43914-4-sv@linux.ibm.com>

On Fri, Mar 18, 2022 at 04:21:40PM +0530, Sathvika Vasireddy wrote:
> This patch adds powerpc specific functions required for
> 'objtool mcount' to work, and enables mcount for ppc.

I would love to see more objtool enablement for Power :-)


> diff --git a/tools/objtool/arch/powerpc/include/arch/elf.h b/tools/objtool/arch/powerpc/include/arch/elf.h
> new file mode 100644
> index 000000000000..3c8ebb7d2a6b
> --- /dev/null
> +++ b/tools/objtool/arch/powerpc/include/arch/elf.h
> @@ -0,0 +1,8 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +
> +#ifndef _OBJTOOL_ARCH_ELF
> +#define _OBJTOOL_ARCH_ELF
> +
> +#define R_NONE R_PPC_NONE
> +
> +#endif /* _OBJTOOL_ARCH_ELF */
> diff --git a/tools/objtool/utils.c b/tools/objtool/utils.c
> index d1fc6a123a6e..c9c14fa0dfd7 100644
> --- a/tools/objtool/utils.c
> +++ b/tools/objtool/utils.c
> @@ -179,11 +179,29 @@ int create_mcount_loc_sections(struct objtool_file *file)
>  		loc = (unsigned long *)sec->data->d_buf + idx;
>  		memset(loc, 0, sizeof(unsigned long));
>  
> -		if (elf_add_reloc_to_insn(file->elf, sec,
> -					  idx * sizeof(unsigned long),
> -					  R_X86_64_64,
> -					  insn->sec, insn->offset))
> -			return -1;
> +		if (file->elf->ehdr.e_machine == EM_X86_64) {
> +			if (elf_add_reloc_to_insn(file->elf, sec,
> +						  idx * sizeof(unsigned long),
> +						  R_X86_64_64,
> +						  insn->sec, insn->offset))
> +				return -1;
> +		}
> +
> +		if (file->elf->ehdr.e_machine == EM_PPC64) {
> +			if (elf_add_reloc_to_insn(file->elf, sec,
> +						  idx * sizeof(unsigned long),
> +						  R_PPC64_ADDR64,
> +						  insn->sec, insn->offset))
> +				return -1;
> +		}
> +
> +		if (file->elf->ehdr.e_machine == EM_PPC) {
> +			if (elf_add_reloc_to_insn(file->elf, sec,
> +						  idx * sizeof(unsigned long),
> +						  R_PPC_ADDR32,
> +						  insn->sec, insn->offset))
> +				return -1;
> +		}

It appears to me that repeating this code 3 times doesn't really scale
well, how about we introduce a helper like:


int elf_reloc_type_long(struct elf *elf)
{
	switch (elf->ehdr.e_machine) {
	case EM_X86_64:
		return R_X86_64_64;
	case EM_PPC64:
		return R_PPC64_ADDR64;
	case EM_PPC:
		return R_PPC_ADDR32;
	default:
		WARN("unknown machine...")
		exit(-1);
	}
}

		if (elf_add_reloc_to_insn(file->elf, sec,
					  idx * sizeof(unsigned long),
					  elf_reloc_type_long(file->elf),
					  insn->sec, insn->offset))
			return -1;


  reply	other threads:[~2022-03-18 12:27 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-18 10:51 [RFC PATCH 0/3] objtool: Add mcount sub-command Sathvika Vasireddy
2022-03-18 10:51 ` [RFC PATCH 1/3] objtool: Move common code to utils.c Sathvika Vasireddy
2022-03-23 18:02   ` Miroslav Benes
2022-03-18 10:51 ` [RFC PATCH 2/3] objtool: Enable and implement 'mcount' subcommand Sathvika Vasireddy
2022-03-21  7:06   ` Christophe Leroy
2022-03-21  8:19     ` Naveen N. Rao
2022-03-21  8:26       ` Christophe Leroy
2022-03-21  9:48         ` Naveen N. Rao
2022-03-18 10:51 ` [RFC PATCH 3/3] objtool/mcount: Add powerpc specific functions Sathvika Vasireddy
2022-03-18 12:26   ` Peter Zijlstra [this message]
2022-03-18 13:59     ` Christophe Leroy
2022-03-21  2:27       ` Michael Ellerman
2022-03-21  6:47         ` Christophe Leroy
2022-03-21  7:46         ` Christophe Leroy
2022-03-21  7:56         ` Christophe Leroy
2022-03-21  8:30           ` Christophe Leroy
2022-03-21  8:59             ` Christophe Leroy
2022-03-26  7:58           ` Christophe Leroy
2022-03-21  6:25     ` Naveen N. Rao
2022-03-27  9:09     ` Christophe Leroy
2022-03-28 19:59       ` Josh Poimboeuf
2022-03-28 20:14         ` Peter Zijlstra
2022-03-28 20:15           ` Peter Zijlstra
2022-03-28 20:21           ` Josh Poimboeuf
2022-03-29 12:01         ` Michael Ellerman
2022-03-29 17:32           ` Christophe Leroy
2022-03-30  4:26             ` Josh Poimboeuf
2022-03-30 18:40             ` Naveen N. Rao
2022-05-12 14:52         ` Christophe Leroy
2022-05-12 15:12           ` Josh Poimboeuf
2022-05-21  9:38             ` Christophe Leroy
2022-05-21 10:57               ` Peter Zijlstra
2022-05-23  5:39                 ` Naveen N. Rao
2022-03-19  1:35 ` [RFC PATCH 0/3] objtool: Add mcount sub-command Josh Poimboeuf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YjR6kHq4c/rjCTpr@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=aik@ozlabs.ru \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mpe@ellerman.id.au \
    --cc=naveen.n.rao@linux.vnet.ibm.com \
    --cc=rostedt@goodmis.org \
    --cc=sv@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome