From nobody Sun Feb 8 12:43:15 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B21BC77B7A for ; Tue, 30 May 2023 17:21:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233322AbjE3RVu (ORCPT ); Tue, 30 May 2023 13:21:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232411AbjE3RVh (ORCPT ); Tue, 30 May 2023 13:21:37 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DE49E8 for ; Tue, 30 May 2023 10:21:34 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 940A263120 for ; Tue, 30 May 2023 17:21:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C249EC4339B; Tue, 30 May 2023 17:21:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685467293; bh=ObRta/cmQf+Y5yZ8nzlOMvBFJEPR6qPtpNwKwUR6Mh8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HSPomr8CpVJD+AazpC7kUdFbyw14WTCcI1+eg8EUGQE6UUKPaNDK+rgIN0SpFe5H/ VWkO7QXG6a7+2pETEQmgmFP0QQP7pjegOjvFPYZHwgPW25ovyVxQKijyqF+PrafkKv rVhNWkuFOhq4V264zXO8d4WSG/WLkbGrP43kkez86QAWogNWTvT4UqdzxbvnddzyNy bp8wzdxDMdk/Kj6L4/kkht9Cby0Md9UjZEshadpiAx20mrwpc1zjxpSeubIMOASSZ4 UGKNYVcm5CnafrOJAJKhZm/vRwsxOh/lptSr4wi9VcmkDk0p3dVw3V7lftQ9hyfY0S nEnFCURNjOpwg== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Miroslav Benes Subject: [PATCH 03/22] objtool: Improve reloc naming Date: Tue, 30 May 2023 10:20:55 -0700 Message-Id: <8b790e403df46f445c21003e7893b8f53b99a6f3.1685464332.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" - The term "reloc" is overloaded to mean both "an instance of struct reloc" and "a reloc section". Change the latter to "rsec". - For variable names, use "sec" for regular sections and "rsec" for rela sections to prevent them getting mixed up. - For struct reloc variables, use "reloc" instead of "rel" everywhere for consistency. Signed-off-by: Josh Poimboeuf --- tools/objtool/check.c | 134 +++++++++++------------ tools/objtool/elf.c | 164 ++++++++++++++-------------- tools/objtool/include/objtool/elf.h | 2 +- 3 files changed, 151 insertions(+), 149 deletions(-) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index bc6771550423..189b4161e713 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -493,7 +493,7 @@ static int add_pv_ops(struct objtool_file *file, const = char *symname) { struct symbol *sym, *func; unsigned long off, end; - struct reloc *rel; + struct reloc *reloc; int idx; =20 sym =3D find_symbol_by_name(file->elf, symname); @@ -503,19 +503,19 @@ static int add_pv_ops(struct objtool_file *file, cons= t char *symname) off =3D sym->offset; end =3D off + sym->len; for (;;) { - rel =3D find_reloc_by_dest_range(file->elf, sym->sec, off, end - off); - if (!rel) + reloc =3D find_reloc_by_dest_range(file->elf, sym->sec, off, end - off); + if (!reloc) break; =20 - func =3D rel->sym; + func =3D reloc->sym; if (func->type =3D=3D STT_SECTION) - func =3D find_symbol_by_offset(rel->sym->sec, rel->addend); + func =3D find_symbol_by_offset(reloc->sym->sec, reloc->addend); =20 - idx =3D (rel->offset - sym->offset) / sizeof(unsigned long); + idx =3D (reloc->offset - sym->offset) / sizeof(unsigned long); =20 objtool_pv_add(file, idx, func); =20 - off =3D rel->offset + 1; + off =3D reloc->offset + 1; if (off > end) break; } @@ -580,20 +580,20 @@ static struct instruction *find_last_insn(struct objt= ool_file *file, */ static int add_dead_ends(struct objtool_file *file) { - struct section *sec; + struct section *rsec; struct reloc *reloc; struct instruction *insn; =20 /* * Check for manually annotated dead ends. */ - sec =3D find_section_by_name(file->elf, ".rela.discard.unreachable"); - if (!sec) + rsec =3D find_section_by_name(file->elf, ".rela.discard.unreachable"); + if (!rsec) goto reachable; =20 - list_for_each_entry(reloc, &sec->reloc_list, list) { + list_for_each_entry(reloc, &rsec->reloc_list, list) { if (reloc->sym->type !=3D STT_SECTION) { - WARN("unexpected relocation symbol type in %s", sec->name); + WARN("unexpected relocation symbol type in %s", rsec->name); return -1; } insn =3D find_insn(file, reloc->sym->sec, reloc->addend); @@ -622,13 +622,13 @@ static int add_dead_ends(struct objtool_file *file) * GCC doesn't know the "ud2" is fatal, so it generates code as if it's * not a dead end. */ - sec =3D find_section_by_name(file->elf, ".rela.discard.reachable"); - if (!sec) + rsec =3D find_section_by_name(file->elf, ".rela.discard.reachable"); + if (!rsec) return 0; =20 - list_for_each_entry(reloc, &sec->reloc_list, list) { + list_for_each_entry(reloc, &rsec->reloc_list, list) { if (reloc->sym->type !=3D STT_SECTION) { - WARN("unexpected relocation symbol type in %s", sec->name); + WARN("unexpected relocation symbol type in %s", rsec->name); return -1; } insn =3D find_insn(file, reloc->sym->sec, reloc->addend); @@ -1043,15 +1043,15 @@ static int create_direct_call_sections(struct objto= ol_file *file) static void add_ignores(struct objtool_file *file) { struct instruction *insn; - struct section *sec; + struct section *rsec; struct symbol *func; struct reloc *reloc; =20 - sec =3D find_section_by_name(file->elf, ".rela.discard.func_stack_frame_n= on_standard"); - if (!sec) + rsec =3D find_section_by_name(file->elf, ".rela.discard.func_stack_frame_= non_standard"); + if (!rsec) return; =20 - list_for_each_entry(reloc, &sec->reloc_list, list) { + list_for_each_entry(reloc, &rsec->reloc_list, list) { switch (reloc->sym->type) { case STT_FUNC: func =3D reloc->sym; @@ -1064,7 +1064,8 @@ static void add_ignores(struct objtool_file *file) break; =20 default: - WARN("unexpected relocation symbol type in %s: %d", sec->name, reloc->s= ym->type); + WARN("unexpected relocation symbol type in %s: %d", + rsec->name, reloc->sym->type); continue; } =20 @@ -1283,17 +1284,17 @@ static void add_uaccess_safe(struct objtool_file *f= ile) */ static int add_ignore_alternatives(struct objtool_file *file) { - struct section *sec; + struct section *rsec; struct reloc *reloc; struct instruction *insn; =20 - sec =3D find_section_by_name(file->elf, ".rela.discard.ignore_alts"); - if (!sec) + rsec =3D find_section_by_name(file->elf, ".rela.discard.ignore_alts"); + if (!rsec) return 0; =20 - list_for_each_entry(reloc, &sec->reloc_list, list) { + list_for_each_entry(reloc, &rsec->reloc_list, list) { if (reloc->sym->type !=3D STT_SECTION) { - WARN("unexpected relocation symbol type in %s", sec->name); + WARN("unexpected relocation symbol type in %s", rsec->name); return -1; } =20 @@ -2203,7 +2204,7 @@ static void set_func_state(struct cfi_state *state) static int read_unwind_hints(struct objtool_file *file) { struct cfi_state cfi =3D init_cfi; - struct section *sec, *relocsec; + struct section *sec; struct unwind_hint *hint; struct instruction *insn; struct reloc *reloc; @@ -2213,8 +2214,7 @@ static int read_unwind_hints(struct objtool_file *fil= e) if (!sec) return 0; =20 - relocsec =3D sec->reloc; - if (!relocsec) { + if (!sec->rsec) { WARN("missing .rela.discard.unwind_hints section"); return -1; } @@ -2289,15 +2289,15 @@ static int read_unwind_hints(struct objtool_file *f= ile) =20 static int read_noendbr_hints(struct objtool_file *file) { - struct section *sec; struct instruction *insn; + struct section *rsec; struct reloc *reloc; =20 - sec =3D find_section_by_name(file->elf, ".rela.discard.noendbr"); - if (!sec) + rsec =3D find_section_by_name(file->elf, ".rela.discard.noendbr"); + if (!rsec) return 0; =20 - list_for_each_entry(reloc, &sec->reloc_list, list) { + list_for_each_entry(reloc, &rsec->reloc_list, list) { insn =3D find_insn(file, reloc->sym->sec, reloc->sym->offset + reloc->ad= dend); if (!insn) { WARN("bad .discard.noendbr entry"); @@ -2312,17 +2312,17 @@ static int read_noendbr_hints(struct objtool_file *= file) =20 static int read_retpoline_hints(struct objtool_file *file) { - struct section *sec; + struct section *rsec; struct instruction *insn; struct reloc *reloc; =20 - sec =3D find_section_by_name(file->elf, ".rela.discard.retpoline_safe"); - if (!sec) + rsec =3D find_section_by_name(file->elf, ".rela.discard.retpoline_safe"); + if (!rsec) return 0; =20 - list_for_each_entry(reloc, &sec->reloc_list, list) { + list_for_each_entry(reloc, &rsec->reloc_list, list) { if (reloc->sym->type !=3D STT_SECTION) { - WARN("unexpected relocation symbol type in %s", sec->name); + WARN("unexpected relocation symbol type in %s", rsec->name); return -1; } =20 @@ -2348,17 +2348,17 @@ static int read_retpoline_hints(struct objtool_file= *file) =20 static int read_instr_hints(struct objtool_file *file) { - struct section *sec; + struct section *rsec; struct instruction *insn; struct reloc *reloc; =20 - sec =3D find_section_by_name(file->elf, ".rela.discard.instr_end"); - if (!sec) + rsec =3D find_section_by_name(file->elf, ".rela.discard.instr_end"); + if (!rsec) return 0; =20 - list_for_each_entry(reloc, &sec->reloc_list, list) { + list_for_each_entry(reloc, &rsec->reloc_list, list) { if (reloc->sym->type !=3D STT_SECTION) { - WARN("unexpected relocation symbol type in %s", sec->name); + WARN("unexpected relocation symbol type in %s", rsec->name); return -1; } =20 @@ -2371,13 +2371,13 @@ static int read_instr_hints(struct objtool_file *fi= le) insn->instr--; } =20 - sec =3D find_section_by_name(file->elf, ".rela.discard.instr_begin"); - if (!sec) + rsec =3D find_section_by_name(file->elf, ".rela.discard.instr_begin"); + if (!rsec) return 0; =20 - list_for_each_entry(reloc, &sec->reloc_list, list) { + list_for_each_entry(reloc, &rsec->reloc_list, list) { if (reloc->sym->type !=3D STT_SECTION) { - WARN("unexpected relocation symbol type in %s", sec->name); + WARN("unexpected relocation symbol type in %s", rsec->name); return -1; } =20 @@ -2395,17 +2395,17 @@ static int read_instr_hints(struct objtool_file *fi= le) =20 static int read_validate_unret_hints(struct objtool_file *file) { - struct section *sec; + struct section *rsec; struct instruction *insn; struct reloc *reloc; =20 - sec =3D find_section_by_name(file->elf, ".rela.discard.validate_unret"); - if (!sec) + rsec =3D find_section_by_name(file->elf, ".rela.discard.validate_unret"); + if (!rsec) return 0; =20 - list_for_each_entry(reloc, &sec->reloc_list, list) { + list_for_each_entry(reloc, &rsec->reloc_list, list) { if (reloc->sym->type !=3D STT_SECTION) { - WARN("unexpected relocation symbol type in %s", sec->name); + WARN("unexpected relocation symbol type in %s", rsec->name); return -1; } =20 @@ -2424,19 +2424,19 @@ static int read_validate_unret_hints(struct objtool= _file *file) static int read_intra_function_calls(struct objtool_file *file) { struct instruction *insn; - struct section *sec; + struct section *rsec; struct reloc *reloc; =20 - sec =3D find_section_by_name(file->elf, ".rela.discard.intra_function_cal= ls"); - if (!sec) + rsec =3D find_section_by_name(file->elf, ".rela.discard.intra_function_ca= lls"); + if (!rsec) return 0; =20 - list_for_each_entry(reloc, &sec->reloc_list, list) { + list_for_each_entry(reloc, &rsec->reloc_list, list) { unsigned long dest_off; =20 if (reloc->sym->type !=3D STT_SECTION) { WARN("unexpected relocation symbol type in %s", - sec->name); + rsec->name); return -1; } =20 @@ -3332,15 +3332,15 @@ static inline bool func_uaccess_safe(struct symbol = *func) static inline const char *call_dest_name(struct instruction *insn) { static char pvname[19]; - struct reloc *rel; + struct reloc *reloc; int idx; =20 if (insn_call_dest(insn)) return insn_call_dest(insn)->name; =20 - rel =3D insn_reloc(NULL, insn); - if (rel && !strcmp(rel->sym->name, "pv_ops")) { - idx =3D (rel->addend / sizeof(void *)); + reloc =3D insn_reloc(NULL, insn); + if (reloc && !strcmp(reloc->sym->name, "pv_ops")) { + idx =3D (reloc->addend / sizeof(void *)); snprintf(pvname, sizeof(pvname), "pv_ops[%d]", idx); return pvname; } @@ -3351,14 +3351,14 @@ static inline const char *call_dest_name(struct ins= truction *insn) static bool pv_call_dest(struct objtool_file *file, struct instruction *in= sn) { struct symbol *target; - struct reloc *rel; + struct reloc *reloc; int idx; =20 - rel =3D insn_reloc(file, insn); - if (!rel || strcmp(rel->sym->name, "pv_ops")) + reloc =3D insn_reloc(file, insn); + if (!reloc || strcmp(reloc->sym->name, "pv_ops")) return false; =20 - idx =3D (arch_dest_reloc_offset(rel->addend) / sizeof(void *)); + idx =3D (arch_dest_reloc_offset(reloc->addend) / sizeof(void *)); =20 if (file->pv_ops[idx].clean) return true; @@ -4401,7 +4401,7 @@ static int validate_ibt(struct objtool_file *file) if (sec->sh.sh_flags & SHF_EXECINSTR) continue; =20 - if (!sec->reloc) + if (!sec->rsec) continue; =20 /* @@ -4428,7 +4428,7 @@ static int validate_ibt(struct objtool_file *file) strstr(sec->name, "__patchable_function_entries")) continue; =20 - list_for_each_entry(reloc, &sec->reloc->reloc_list, list) + list_for_each_entry(reloc, &sec->rsec->reloc_list, list) warnings +=3D validate_ibt_data_reloc(file, reloc); } =20 diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index 7598c0a2633d..86ae62dfdba2 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -233,17 +233,17 @@ struct reloc *find_reloc_by_dest_range(const struct e= lf *elf, struct section *se unsigned long offset, unsigned int len) { struct reloc *reloc, *r =3D NULL; + struct section *rsec; unsigned long o; =20 - if (!sec->reloc) + rsec =3D sec->rsec; + if (!rsec) return NULL; =20 - sec =3D sec->reloc; - for_offset_range(o, offset, offset + len) { elf_hash_for_each_possible(reloc, reloc, hash, - sec_offset_hash(sec, o)) { - if (reloc->sec !=3D sec) + sec_offset_hash(rsec, o)) { + if (reloc->sec !=3D rsec) continue; =20 if (reloc->offset >=3D offset && reloc->offset < offset + len) { @@ -534,7 +534,7 @@ static int read_symbols(struct elf *elf) } =20 static struct section *elf_create_reloc_section(struct elf *elf, - struct section *base, + struct section *sec, int reltype); =20 int elf_add_reloc(struct elf *elf, struct section *sec, unsigned long offs= et, @@ -542,7 +542,7 @@ int elf_add_reloc(struct elf *elf, struct section *sec,= unsigned long offset, { struct reloc *reloc; =20 - if (!sec->reloc && !elf_create_reloc_section(elf, sec, SHT_RELA)) + if (!sec->rsec && !elf_create_reloc_section(elf, sec, SHT_RELA)) return -1; =20 reloc =3D malloc(sizeof(*reloc)); @@ -552,18 +552,18 @@ int elf_add_reloc(struct elf *elf, struct section *se= c, unsigned long offset, } memset(reloc, 0, sizeof(*reloc)); =20 - reloc->sec =3D sec->reloc; + reloc->sec =3D sec->rsec; reloc->offset =3D offset; reloc->type =3D type; reloc->sym =3D sym; reloc->addend =3D addend; =20 list_add_tail(&reloc->sym_reloc_entry, &sym->reloc_list); - list_add_tail(&reloc->list, &sec->reloc->reloc_list); + list_add_tail(&reloc->list, &sec->rsec->reloc_list); elf_hash_add(reloc, &reloc->hash, reloc_hash(reloc)); =20 - sec->reloc->sh.sh_size +=3D sec->reloc->sh.sh_entsize; - sec->reloc->changed =3D true; + sec->rsec->sh.sh_size +=3D sec->rsec->sh.sh_entsize; + sec->rsec->changed =3D true; =20 return 0; } @@ -865,9 +865,9 @@ int elf_add_reloc_to_insn(struct elf *elf, struct secti= on *sec, return elf_add_reloc(elf, sec, offset, type, sym, addend); } =20 -static int read_rel_reloc(struct section *sec, int i, struct reloc *reloc,= unsigned int *symndx) +static int read_rel_reloc(struct section *rsec, int i, struct reloc *reloc= , unsigned int *symndx) { - if (!gelf_getrel(sec->data, i, &reloc->rel)) { + if (!gelf_getrel(rsec->data, i, &reloc->rel)) { WARN_ELF("gelf_getrel"); return -1; } @@ -878,9 +878,9 @@ static int read_rel_reloc(struct section *sec, int i, s= truct reloc *reloc, unsig return 0; } =20 -static int read_rela_reloc(struct section *sec, int i, struct reloc *reloc= , unsigned int *symndx) +static int read_rela_reloc(struct section *rsec, int i, struct reloc *relo= c, unsigned int *symndx) { - if (!gelf_getrela(sec->data, i, &reloc->rela)) { + if (!gelf_getrela(rsec->data, i, &reloc->rela)) { WARN_ELF("gelf_getrela"); return -1; } @@ -894,7 +894,7 @@ static int read_rela_reloc(struct section *sec, int i, = struct reloc *reloc, unsi static int read_relocs(struct elf *elf) { unsigned long nr_reloc, max_reloc =3D 0, tot_reloc =3D 0; - struct section *sec; + struct section *rsec; struct reloc *reloc; unsigned int symndx; struct symbol *sym; @@ -903,51 +903,52 @@ static int read_relocs(struct elf *elf) if (!elf_alloc_hash(reloc, elf->text_size / 16)) return -1; =20 - list_for_each_entry(sec, &elf->sections, list) { - if ((sec->sh.sh_type !=3D SHT_RELA) && - (sec->sh.sh_type !=3D SHT_REL)) + list_for_each_entry(rsec, &elf->sections, list) { + if ((rsec->sh.sh_type !=3D SHT_RELA) && + (rsec->sh.sh_type !=3D SHT_REL)) continue; =20 - sec->base =3D find_section_by_index(elf, sec->sh.sh_info); - if (!sec->base) { + rsec->base =3D find_section_by_index(elf, rsec->sh.sh_info); + if (!rsec->base) { WARN("can't find base section for reloc section %s", - sec->name); + rsec->name); return -1; } =20 - sec->base->reloc =3D sec; + rsec->base->rsec =3D rsec; =20 nr_reloc =3D 0; - sec->reloc_data =3D calloc(sec->sh.sh_size / sec->sh.sh_entsize, sizeof(= *reloc)); - if (!sec->reloc_data) { + rsec->reloc_data =3D calloc(rsec->sh.sh_size / rsec->sh.sh_entsize, + sizeof(*reloc)); + if (!rsec->reloc_data) { perror("calloc"); return -1; } - for (i =3D 0; i < sec->sh.sh_size / sec->sh.sh_entsize; i++) { - reloc =3D &sec->reloc_data[i]; - switch (sec->sh.sh_type) { + for (i =3D 0; i < rsec->sh.sh_size / rsec->sh.sh_entsize; i++) { + reloc =3D &rsec->reloc_data[i]; + switch (rsec->sh.sh_type) { case SHT_REL: - if (read_rel_reloc(sec, i, reloc, &symndx)) + if (read_rel_reloc(rsec, i, reloc, &symndx)) return -1; break; case SHT_RELA: - if (read_rela_reloc(sec, i, reloc, &symndx)) + if (read_rela_reloc(rsec, i, reloc, &symndx)) return -1; break; default: return -1; } =20 - reloc->sec =3D sec; + reloc->sec =3D rsec; reloc->idx =3D i; reloc->sym =3D sym =3D find_symbol_by_index(elf, symndx); if (!reloc->sym) { WARN("can't find reloc entry symbol %d for %s", - symndx, sec->name); + symndx, rsec->name); return -1; } =20 list_add_tail(&reloc->sym_reloc_entry, &sym->reloc_list); - list_add_tail(&reloc->list, &sec->reloc_list); + list_add_tail(&reloc->list, &rsec->reloc_list); elf_hash_add(reloc, &reloc->hash, reloc_hash(reloc)); =20 nr_reloc++; @@ -1140,40 +1141,41 @@ struct section *elf_create_section(struct elf *elf,= const char *name, return sec; } =20 -static struct section *elf_create_rel_reloc_section(struct elf *elf, struc= t section *base) +static struct section *elf_create_rel_reloc_section(struct elf *elf, + struct section *sec) { char *relocname; - struct section *sec; + struct section *rsec; =20 - relocname =3D malloc(strlen(base->name) + strlen(".rel") + 1); + relocname =3D malloc(strlen(sec->name) + strlen(".rel") + 1); if (!relocname) { perror("malloc"); return NULL; } strcpy(relocname, ".rel"); - strcat(relocname, base->name); + strcat(relocname, sec->name); =20 - sec =3D elf_create_section(elf, relocname, sizeof(GElf_Rel), 0); + rsec =3D elf_create_section(elf, relocname, sizeof(GElf_Rel), 0); free(relocname); - if (!sec) + if (!rsec) return NULL; =20 - base->reloc =3D sec; - sec->base =3D base; + sec->rsec =3D rsec; + rsec->base =3D sec; =20 - sec->sh.sh_type =3D SHT_REL; - sec->sh.sh_addralign =3D 8; - sec->sh.sh_link =3D find_section_by_name(elf, ".symtab")->idx; - sec->sh.sh_info =3D base->idx; - sec->sh.sh_flags =3D SHF_INFO_LINK; + rsec->sh.sh_type =3D SHT_REL; + rsec->sh.sh_addralign =3D 8; + rsec->sh.sh_link =3D find_section_by_name(elf, ".symtab")->idx; + rsec->sh.sh_info =3D sec->idx; + rsec->sh.sh_flags =3D SHF_INFO_LINK; =20 - return sec; + return rsec; } =20 static struct section *elf_create_rela_reloc_section(struct elf *elf, stru= ct section *base) { char *relocname; - struct section *sec; + struct section *rsec; int addrsize =3D elf_class_addrsize(elf); =20 relocname =3D malloc(strlen(base->name) + strlen(".rela") + 1); @@ -1185,23 +1187,23 @@ static struct section *elf_create_rela_reloc_sectio= n(struct elf *elf, struct sec strcat(relocname, base->name); =20 if (addrsize =3D=3D sizeof(u32)) - sec =3D elf_create_section(elf, relocname, sizeof(Elf32_Rela), 0); + rsec =3D elf_create_section(elf, relocname, sizeof(Elf32_Rela), 0); else - sec =3D elf_create_section(elf, relocname, sizeof(GElf_Rela), 0); + rsec =3D elf_create_section(elf, relocname, sizeof(GElf_Rela), 0); free(relocname); - if (!sec) + if (!rsec) return NULL; =20 - base->reloc =3D sec; - sec->base =3D base; + base->rsec =3D rsec; + rsec->base =3D base; =20 - sec->sh.sh_type =3D SHT_RELA; - sec->sh.sh_addralign =3D addrsize; - sec->sh.sh_link =3D find_section_by_name(elf, ".symtab")->idx; - sec->sh.sh_info =3D base->idx; - sec->sh.sh_flags =3D SHF_INFO_LINK; + rsec->sh.sh_type =3D SHT_RELA; + rsec->sh.sh_addralign =3D addrsize; + rsec->sh.sh_link =3D find_section_by_name(elf, ".symtab")->idx; + rsec->sh.sh_info =3D base->idx; + rsec->sh.sh_flags =3D SHF_INFO_LINK; =20 - return sec; + return rsec; } =20 static struct section *elf_create_reloc_section(struct elf *elf, @@ -1215,28 +1217,28 @@ static struct section *elf_create_reloc_section(str= uct elf *elf, } } =20 -static int elf_rebuild_rel_reloc_section(struct section *sec) +static int elf_rebuild_rel_reloc_section(struct section *rsec) { struct reloc *reloc; int idx =3D 0; void *buf; =20 /* Allocate a buffer for relocations */ - buf =3D malloc(sec->sh.sh_size); + buf =3D malloc(rsec->sh.sh_size); if (!buf) { perror("malloc"); return -1; } =20 - sec->data->d_buf =3D buf; - sec->data->d_size =3D sec->sh.sh_size; - sec->data->d_type =3D ELF_T_REL; + rsec->data->d_buf =3D buf; + rsec->data->d_size =3D rsec->sh.sh_size; + rsec->data->d_type =3D ELF_T_REL; =20 idx =3D 0; - list_for_each_entry(reloc, &sec->reloc_list, list) { + list_for_each_entry(reloc, &rsec->reloc_list, list) { reloc->rel.r_offset =3D reloc->offset; reloc->rel.r_info =3D GELF_R_INFO(reloc->sym->idx, reloc->type); - if (!gelf_update_rel(sec->data, idx, &reloc->rel)) { + if (!gelf_update_rel(rsec->data, idx, &reloc->rel)) { WARN_ELF("gelf_update_rel"); return -1; } @@ -1246,29 +1248,29 @@ static int elf_rebuild_rel_reloc_section(struct sec= tion *sec) return 0; } =20 -static int elf_rebuild_rela_reloc_section(struct section *sec) +static int elf_rebuild_rela_reloc_section(struct section *rsec) { struct reloc *reloc; int idx =3D 0; void *buf; =20 /* Allocate a buffer for relocations with addends */ - buf =3D malloc(sec->sh.sh_size); + buf =3D malloc(rsec->sh.sh_size); if (!buf) { perror("malloc"); return -1; } =20 - sec->data->d_buf =3D buf; - sec->data->d_size =3D sec->sh.sh_size; - sec->data->d_type =3D ELF_T_RELA; + rsec->data->d_buf =3D buf; + rsec->data->d_size =3D rsec->sh.sh_size; + rsec->data->d_type =3D ELF_T_RELA; =20 idx =3D 0; - list_for_each_entry(reloc, &sec->reloc_list, list) { + list_for_each_entry(reloc, &rsec->reloc_list, list) { reloc->rela.r_offset =3D reloc->offset; reloc->rela.r_addend =3D reloc->addend; reloc->rela.r_info =3D GELF_R_INFO(reloc->sym->idx, reloc->type); - if (!gelf_update_rela(sec->data, idx, &reloc->rela)) { + if (!gelf_update_rela(rsec->data, idx, &reloc->rela)) { WARN_ELF("gelf_update_rela"); return -1; } @@ -1278,11 +1280,11 @@ static int elf_rebuild_rela_reloc_section(struct se= ction *sec) return 0; } =20 -static int elf_rebuild_reloc_section(struct elf *elf, struct section *sec) +static int elf_rebuild_reloc_section(struct elf *elf, struct section *rsec) { - switch (sec->sh.sh_type) { - case SHT_REL: return elf_rebuild_rel_reloc_section(sec); - case SHT_RELA: return elf_rebuild_rela_reloc_section(sec); + switch (rsec->sh.sh_type) { + case SHT_REL: return elf_rebuild_rel_reloc_section(rsec); + case SHT_RELA: return elf_rebuild_rela_reloc_section(rsec); default: return -1; } } @@ -1308,13 +1310,13 @@ int elf_write_insn(struct elf *elf, struct section = *sec, =20 int elf_write_reloc(struct elf *elf, struct reloc *reloc) { - struct section *sec =3D reloc->sec; + struct section *rsec =3D reloc->sec; =20 - if (sec->sh.sh_type =3D=3D SHT_REL) { + if (rsec->sh.sh_type =3D=3D SHT_REL) { reloc->rel.r_info =3D GELF_R_INFO(reloc->sym->idx, reloc->type); reloc->rel.r_offset =3D reloc->offset; =20 - if (!gelf_update_rel(sec->data, reloc->idx, &reloc->rel)) { + if (!gelf_update_rel(rsec->data, reloc->idx, &reloc->rel)) { WARN_ELF("gelf_update_rel"); return -1; } @@ -1323,7 +1325,7 @@ int elf_write_reloc(struct elf *elf, struct reloc *re= loc) reloc->rela.r_addend =3D reloc->addend; reloc->rela.r_offset =3D reloc->offset; =20 - if (!gelf_update_rela(sec->data, reloc->idx, &reloc->rela)) { + if (!gelf_update_rela(rsec->data, reloc->idx, &reloc->rela)) { WARN_ELF("gelf_update_rela"); return -1; } diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/ob= jtool/elf.h index 2c28aeeb3cb2..a4e43a69f922 100644 --- a/tools/objtool/include/objtool/elf.h +++ b/tools/objtool/include/objtool/elf.h @@ -33,7 +33,7 @@ struct section { struct rb_root_cached symbol_tree; struct list_head symbol_list; struct list_head reloc_list; - struct section *base, *reloc; + struct section *base, *rsec; struct symbol *sym; Elf_Data *data; char *name; --=20 2.40.1