Subject: Re: [PATCH v2 10/16] objtool: Use target file class size instead of a compiled constant

From: Peter Zijlstra <[email-masked]>
Date: Thu, 1 Sep 2022 21:23:52 +0200

On Mon, Aug 29, 2022 at 11:22:17AM +0530, Sathvika Vasireddy wrote:
> From: Christophe Leroy <[email-masked]>
> 
> In order to allow using objtool on cross-built kernels,
> determine size of long from elf data instead of using
> sizeof(long) at build time.
> 
> For the time being this covers only mcount.
> 
> Signed-off-by: Christophe Leroy <[email-masked]>

Acked-by: Peter Zijlstra (Intel) <[email-masked]>

> ---
>  tools/objtool/check.c               | 16 +++++++++-------
>  tools/objtool/elf.c                 |  8 ++++++--
>  tools/objtool/include/objtool/elf.h |  8 ++++++++
>  3 files changed, 23 insertions(+), 9 deletions(-)
> 
> diff --git a/tools/objtool/check.c b/tools/objtool/check.c
> index a948b2551520..0ecf41ee73f0 100644
> --- a/tools/objtool/check.c
> +++ b/tools/objtool/check.c
> @@ -851,9 +851,9 @@ static int create_ibt_endbr_seal_sections(struct objtool_file *file)
>  static int create_mcount_loc_sections(struct objtool_file *file)
>  {
>  	struct section *sec;
> -	unsigned long *loc;
>  	struct instruction *insn;
>  	int idx;
> +	int addrsize = elf_class_addrsize(file->elf);

If there is a respin, please make this a reverse-x-mas-tree thingy.

>  
>  	sec = find_section_by_name(file->elf, "__mcount_loc");
>  	if (sec) {
> @@ -869,23 +869,25 @@ static int create_mcount_loc_sections(struct objtool_file *file)

> --- a/tools/objtool/elf.c
> +++ b/tools/objtool/elf.c
> @@ -1124,6 +1124,7 @@ static struct section *elf_create_rela_reloc_section(struct elf *elf, struct sec
>  {
>  	char *relocname;
>  	struct section *sec;
> +	int addrsize = elf_class_addrsize(elf);
>  

idem.