Re: [PATCH v2 5/8] objtool: reduce memory usage of struct reloc

From: Josh Poimboeuf
Date: Mon Jan 30 2023 - 19:00:04 EST


On Tue, Dec 27, 2022 at 04:01:01PM +0000, Thomas Weißschuh wrote:
> void elf_reloc_set_type(struct reloc *reloc, int type)
> {
> + if (type >= (1U << (8 * sizeof(reloc->type))))
> + WARN("reloc->type out of range: %d", type);
> +
> reloc->type = type;
> }
> diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/objtool/elf.h
> index 33ec6cf72325..2b5becad5a0a 100644
> --- a/tools/objtool/include/objtool/elf.h
> +++ b/tools/objtool/include/objtool/elf.h
> @@ -77,10 +77,10 @@ struct reloc {
> struct symbol *sym;
> struct list_head sym_reloc_entry;
> unsigned long offset;
> - unsigned int type;
> s64 addend;
> int idx;
> bool jump_table_start;
> + unsigned char type;
> };

I'd rather not because

a) the helper function isn't very intuitive and we'll probably forget
to use it

b) some arches need more than 256 types (see for example aarch64 which
objtool may need to support one of these days)

That said, feel free to rearrange the struct fields to at least get some
of those bytes back.

--
Josh