objtool: Use section/symbol type helpers
PATCH 1/1 objtool: Use section/symbol type helpers
Commit 25eac74b6bdb ("objtool: Add section/symbol type helpers") introduced several helper macros to improve code readability.
Update the remaining open-coded checks in check.c, disas.c, elf.c, and klp-diff.c to use these new helpers.
Signed-off-by Wentong Tian <[email protected]>
--- tools/objtool/check.c | 4 ++-- tools/objtool/disas.c | 6 +++--- tools/objtool/elf.c | 6 +++--- tools/objtool/klp-diff.c | 8 ++++---- 4 files changed, 12 insertions(+), 12 deletions(-)
tools/objtool/check.c +2 -2
@@ -4251,8 +4251,8 @@ static int validate_retpoline(struct objtool_file *file)list_for_each_entry (insn, &file->retpoline_call_list, call_node) {struct symbol *sym = insn->sym; -if (sym && (sym->type ==STT_NOTYPE || - sym->type ==STT_FUNC ) && !sym->nocfi) { +if (sym && (is_notype_sym (sym) || +is_func_sym (sym)) && !sym->nocfi) {struct instruction *prev =prev_insn_same_sym (file, insn);
tools/objtool/disas.c +3 -3
@@ -262,7 +262,7 @@ static void disas_print_addr_reloc(bfd_vma addr, struct disassemble_info *dinfo)* If the relocation symbol is a section name (for example ".bss") * then we try to further resolve the name. */ -if (reloc->sym->type ==STT_SECTION ) { +if (is_sec_sym (reloc->sym)) { str =offstr (reloc->sym->sec, reloc->sym->offset + offset);DINFO_FPRINTF (dinfo,"0x%lx <%s>" , addr, str);free (str);
@@ -578,7 +578,7 @@ static size_t disas_insn_common(struct disas_context *dctx,*/ dinfo->buffer = insn->sec->data->d_buf; dinfo->buffer_vma =0 ; - dinfo->buffer_length = insn->sec->sh.sh_size; + dinfo->buffer_length =sec_size (insn->sec);return disasm (insn->offset, &dctx->info); }
@@ -1229,7 +1229,7 @@ void disas_funcs(struct disas_context *dctx)for_each_sec (dctx->file->elf, sec) { -if (!(sec->sh.sh_flags &SHF_EXECINSTR )) +if (!is_text_sec (sec))continue ;sec_for_each_sym (sec, sym) {
tools/objtool/elf.c +3 -3
@@ -615,7 +615,7 @@ static int read_symbols(struct elf *elf)if (elf_add_symbol (elf, sym))return -1 ; -if (sym->type ==STT_FILE ) +if (is_file_sym (sym)) file = sym;else if (sym->bind ==STB_LOCAL ) sym->file = file;
@@ -1336,7 +1336,7 @@ unsigned int elf_add_string(struct elf *elf, struct section *strtab, const charreturn -1 ; } - offset =ALIGN_UP (strtab->sh.sh_size, strtab->sh.sh_addralign); + offset =ALIGN_UP (sec_size (strtab), strtab->sh.sh_addralign);if (!elf_add_data (elf, strtab, str,strlen (str) +1 ))return -1 ;
@@ -1378,7 +1378,7 @@ void *elf_add_data(struct elf *elf, struct section *sec, const void *data, size_ sec->data->d_size = size; sec->data->d_align =1 ; - offset =ALIGN_UP (sec->sh.sh_size, sec->sh.sh_addralign); + offset =ALIGN_UP (sec_size (sec), sec->sh.sh_addralign); sec->sh.sh_size = offset + size;mark_sec_changed (elf, sec, true);
tools/objtool/klp-diff.c +4 -4
@@ -271,7 +271,7 @@ static bool is_uncorrelated_static_local(struct symbol *sym)*/ static bool is_clang_tmp_label (struct symbol *sym) { -return sym->type ==STT_NOTYPE && +return is_notype_sym (sym) &&is_text_sec (sym->sec) &&strstarts (sym->name,".Ltmp" ) &&isdigit (sym->name[5 ]);
@@ -451,7 +451,7 @@ static unsigned long find_sympos(struct elf *elf, struct symbol *sym)if (sym->bind !=STB_LOCAL )return 0 ; -if (vmlinux && sym->type ==STT_FUNC ) { +if (vmlinux &&is_func_sym (sym)) {/* * HACK: Unfortunately, symbol ordering can differ between * vmlinux.o and vmlinux due to the linker script emitting
@@ -1017,8 +1017,8 @@ static int clone_reloc_klp(struct elfs *e, struct reloc *patched_reloc, sec->name, offset, patched_sym->name, \ addend >=0 ?"+" :"-" ,labs (addend), \sym_type (patched_sym), \ - patched_sym->type ==STT_SECTION ?"" :" " , \ - patched_sym->type ==STT_SECTION ?"" :sym_bind (patched_sym), \ +is_sec_sym (patched_sym) ?"" :" " , \ +is_sec_sym (patched_sym) ?"" :sym_bind (patched_sym), \is_undef_sym (patched_sym) ?" UNDEF" :"" , \ export ?" EXPORTED" :"" , \ klp ? " KLP" : "")
Signature · 1 line
2.34.1
The following commit has been merged into the objtool/core branch of tip:
The following commit has been merged into the objtool/core branch of tip:
Commit-ID: c19c854b307424c745dd6de73eea8db099c79408 Gitweb: https://git.kernel.org/tip/c19c854b307424c745dd6de73eea8db099c79408 Author: Wentong Tian <[email protected]> AuthorDate: Thu, 22 Jan 2026 22:44:04 +08:00 Committer: Josh Poimboeuf <[email protected]> CommitterDate: Fri, 06 Mar 2026 08:08:19 -08:00
objtool: Use section/symbol type helpers
Commit 25eac74b6bdb ("objtool: Add section/symbol type helpers") introduced several helper macros to improve code readability.
Update the remaining open-coded checks in check.c, disas.c, elf.c, and klp-diff.c to use these new helpers.
Signed-off-by Wentong Tian <[email protected]>
Signed-off-by Josh Poimboeuf <[email protected]>
--- tools/objtool/check.c | 4 ++-- tools/objtool/disas.c | 6 +++--- tools/objtool/elf.c | 6 +++--- tools/objtool/klp-diff.c | 8 ++++---- 4 files changed, 12 insertions(+), 12 deletions(-)
tools/objtool/check.c +2 -2
@@ -4293,8 +4293,8 @@ static int validate_retpoline(struct objtool_file *file)list_for_each_entry (insn, &file->retpoline_call_list, call_node) {struct symbol *sym = insn->sym; -if (sym && (sym->type ==STT_NOTYPE || - sym->type ==STT_FUNC ) && !sym->nocfi) { +if (sym && (is_notype_sym (sym) || +is_func_sym (sym)) && !sym->nocfi) {struct instruction *prev =prev_insn_same_sym (file, insn);
tools/objtool/disas.c +3 -3
@@ -264,7 +264,7 @@ static void disas_print_addr_reloc(bfd_vma addr, struct disassemble_info *dinfo)* If the relocation symbol is a section name (for example ".bss") * then we try to further resolve the name. */ -if (reloc->sym->type ==STT_SECTION ) { +if (is_sec_sym (reloc->sym)) { str =offstr (reloc->sym->sec, reloc->sym->offset + offset);DINFO_FPRINTF (dinfo, bfd_vma_fmt, addr, str);free (str);
@@ -580,7 +580,7 @@ static size_t disas_insn_common(struct disas_context *dctx,*/ dinfo->buffer = insn->sec->data->d_buf; dinfo->buffer_vma =0 ; - dinfo->buffer_length = insn->sec->sh.sh_size; + dinfo->buffer_length =sec_size (insn->sec);return disasm (insn->offset, &dctx->info); }
@@ -1231,7 +1231,7 @@ void disas_funcs(struct disas_context *dctx)for_each_sec (dctx->file->elf, sec) { -if (!(sec->sh.sh_flags &SHF_EXECINSTR )) +if (!is_text_sec (sec))continue ;sec_for_each_sym (sec, sym) {
tools/objtool/elf.c +3 -3
@@ -614,7 +614,7 @@ static int read_symbols(struct elf *elf)if (elf_add_symbol (elf, sym))return -1 ; -if (sym->type ==STT_FILE ) +if (is_file_sym (sym)) file = sym;else if (sym->bind ==STB_LOCAL ) sym->file = file;
@@ -1335,7 +1335,7 @@ unsigned int elf_add_string(struct elf *elf, struct section *strtab, const charreturn -1 ; } - offset =ALIGN (strtab->sh.sh_size, strtab->sh.sh_addralign); + offset =ALIGN (sec_size (strtab), strtab->sh.sh_addralign);if (!elf_add_data (elf, strtab, str,strlen (str) +1 ))return -1 ;
@@ -1377,7 +1377,7 @@ void *elf_add_data(struct elf *elf, struct section *sec, const void *data, size_ sec->data->d_size = size; sec->data->d_align =1 ; - offset =ALIGN (sec->sh.sh_size, sec->sh.sh_addralign); + offset =ALIGN (sec_size (sec), sec->sh.sh_addralign); sec->sh.sh_size = offset + size;mark_sec_changed (elf, sec, true);
tools/objtool/klp-diff.c +4 -4
@@ -271,7 +271,7 @@ static bool is_uncorrelated_static_local(struct symbol *sym)*/ static bool is_clang_tmp_label (struct symbol *sym) { -return sym->type ==STT_NOTYPE && +return is_notype_sym (sym) &&is_text_sec (sym->sec) &&strstarts (sym->name,".Ltmp" ) &&isdigit (sym->name[5 ]);
@@ -480,7 +480,7 @@ static unsigned long find_sympos(struct elf *elf, struct symbol *sym)if (sym->bind !=STB_LOCAL )return 0 ; -if (vmlinux && sym->type ==STT_FUNC ) { +if (vmlinux &&is_func_sym (sym)) {/* * HACK: Unfortunately, symbol ordering can differ between * vmlinux.o and vmlinux due to the linker script emitting
@@ -1046,8 +1046,8 @@ static int clone_reloc_klp(struct elfs *e, struct reloc *patched_reloc, sec->name, offset, patched_sym->name, \ addend >=0 ?"+" :"-" ,labs (addend), \sym_type (patched_sym), \ - patched_sym->type ==STT_SECTION ?"" :" " , \ - patched_sym->type ==STT_SECTION ?"" :sym_bind (patched_sym), \ +is_sec_sym (patched_sym) ?"" :" " , \ +is_sec_sym (patched_sym) ?"" :sym_bind (patched_sym), \is_undef_sym (patched_sym) ?" UNDEF" :"" , \ export ?" EXPORTED" :"" , \ klp ? " KLP" : "")