From ec24b927c1fbfc91cf7a48276d9fd92072b17d3b Mon Sep 17 00:00:00 2001 From: Josh Poimboeuf Date: Tue, 30 May 2023 10:21:12 -0700 Subject: objtool: Get rid of reloc->rel[a] Get the relocation entry info from the underlying rsec->data. With allyesconfig + CONFIG_DEBUG_INFO: - Before: peak heap memory consumption: 35.12G - After: peak heap memory consumption: 29.93G Link: https://lore.kernel.org/r/2be32323de6d8cc73179ee0ff14b71f4e7cefaa0.1685464332.git.jpoimboe@kernel.org Signed-off-by: Josh Poimboeuf --- tools/objtool/elf.c | 60 +++++++---------------------------------------------- 1 file changed, 7 insertions(+), 53 deletions(-) (limited to 'tools/objtool/elf.c') diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index 04038b1324cf..54d182ddc4bb 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -575,11 +575,8 @@ static int elf_update_sym_relocs(struct elf *elf, struct symbol *sym) { struct reloc *reloc; - for (reloc = sym->relocs; reloc; reloc = reloc->sym_next_reloc) { - reloc->rel.r_info = GELF_R_INFO(reloc->sym->idx, reloc_type(reloc)); - if (elf_write_reloc(elf, reloc)) - return -1; - } + for (reloc = sym->relocs; reloc; reloc = reloc->sym_next_reloc) + set_reloc_sym(elf, reloc, reloc->sym->idx); return 0; } @@ -869,12 +866,10 @@ static struct reloc *elf_init_reloc(struct elf *elf, struct section *rsec, reloc->sec = rsec; reloc->sym = sym; - reloc->rel.r_offset = offset; - reloc->rel.r_info = GELF_R_INFO(sym->idx, type); - reloc->rela.r_addend = addend; - - if (elf_write_reloc(elf, reloc)) - return NULL; + set_reloc_offset(elf, reloc, offset); + set_reloc_sym(elf, reloc, sym->idx); + set_reloc_type(elf, reloc, type); + set_reloc_addend(elf, reloc, addend); elf_hash_add(reloc, &reloc->hash, reloc_hash(reloc)); reloc->sym_next_reloc = sym->relocs; @@ -932,24 +927,6 @@ struct reloc *elf_init_reloc_data_sym(struct elf *elf, struct section *sec, elf_data_rela_type(elf)); } -static int read_reloc(struct section *rsec, int i, struct reloc *reloc) -{ - bool rela = rsec->sh.sh_type == SHT_RELA; - void *retp; - - if (rela) - retp = gelf_getrela(rsec->data, i, &reloc->rela); - else - retp = gelf_getrel(rsec->data, i, &reloc->rel); - - if (!retp) { - WARN_ELF("gelf_getrela"); - return -1; - } - - return 0; -} - static int read_relocs(struct elf *elf) { unsigned long nr_reloc, max_reloc = 0; @@ -984,11 +961,8 @@ static int read_relocs(struct elf *elf) for (i = 0; i < sec_num_entries(rsec); i++) { reloc = &rsec->relocs[i]; - if (read_reloc(rsec, i, reloc)) - return -1; - reloc->sec = rsec; - symndx = GELF_R_SYM(reloc->rel.r_info); + symndx = reloc_sym(reloc); reloc->sym = sym = find_symbol_by_index(elf, symndx); if (!reloc->sym) { WARN("can't find reloc entry symbol %d for %s", @@ -1261,26 +1235,6 @@ int elf_write_insn(struct elf *elf, struct section *sec, return 0; } -int elf_write_reloc(struct elf *elf, struct reloc *reloc) -{ - struct section *rsec = reloc->sec; - int ret; - - if (rsec->sh.sh_type == SHT_RELA) - ret = gelf_update_rela(rsec->data, reloc_idx(reloc), &reloc->rela); - else - ret = gelf_update_rel(rsec->data, reloc_idx(reloc), &reloc->rel); - - if (!ret) { - WARN_ELF("gelf_update_rela"); - return -1; - } - - mark_sec_changed(elf, rsec, true); - - return 0; -} - /* * When Elf_Scn::sh_size is smaller than the combined Elf_Data::d_size * do you: -- cgit v1.2.3