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

From: Thomas Weißschuh
Date: Tue Dec 27 2022 - 11:04:01 EST


Use a smaller type for the relocation type and move it to a location in
the structure where it avoids wasted padding bytes.

Technically ELF could use up to four bytes for the type.
But until now only types up to number 43 have been defined.

Reduce the size of struct reloc on x86_64 from 120 to 112 bytes.
This structure is allocated a lot and never freed.

This reduces maximum memory usage while processing vmlinux.o from
3035668 KB to 2919716 KB (-3.8%) on my notebooks "localmodconfig".

Signed-off-by: Thomas Weißschuh <linux@xxxxxxxxxxxxxx>
---
tools/objtool/elf.c | 3 +++
tools/objtool/include/objtool/elf.h | 2 +-
2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index ee355beb0d82..182452adaa71 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -1474,5 +1474,8 @@ void elf_close(struct elf *elf)

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;
};

void elf_reloc_set_type(struct reloc *reloc, int type);

--
2.39.0