summaryrefslogtreecommitdiff
path: root/tools/objtool/check.c
diff options
context:
space:
mode:
authorJosh Poimboeuf <jpoimboe@kernel.org>2025-09-17 09:03:36 -0700
committerJosh Poimboeuf <jpoimboe@kernel.org>2025-10-14 14:45:25 -0700
commit25eac74b6bdbf6d15911b582e747e8ad12fcbf8f (patch)
treee5778a3824d3fffdfd0750216c36cee6b6bee1ab /tools/objtool/check.c
parent96eceff331ea535b763b161df01300bbfd93b372 (diff)
objtool: Add section/symbol type helpers
Add some helper macros to improve readability. Acked-by: Petr Mladek <pmladek@suse.com> Tested-by: Joe Lawrence <joe.lawrence@redhat.com> Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
Diffstat (limited to 'tools/objtool/check.c')
-rw-r--r--tools/objtool/check.c58
1 files changed, 29 insertions, 29 deletions
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index dbc4fbdb77c4..f38f4a2e4e29 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -261,7 +261,7 @@ static bool __dead_end_function(struct objtool_file *file, struct symbol *func,
if (!func)
return false;
- if (func->bind == STB_GLOBAL || func->bind == STB_WEAK) {
+ if (!is_local_sym(func)) {
if (is_rust_noreturn(func))
return true;
@@ -270,7 +270,7 @@ static bool __dead_end_function(struct objtool_file *file, struct symbol *func,
return true;
}
- if (func->bind == STB_WEAK)
+ if (is_weak_sym(func))
return false;
if (!func->len)
@@ -436,7 +436,7 @@ static int decode_instructions(struct objtool_file *file)
u8 prev_len = 0;
u8 idx = 0;
- if (!(sec->sh.sh_flags & SHF_EXECINSTR))
+ if (!is_text_sec(sec))
continue;
if (strcmp(sec->name, ".altinstr_replacement") &&
@@ -459,7 +459,7 @@ static int decode_instructions(struct objtool_file *file)
if (!strcmp(sec->name, ".init.text") && !opts.module)
sec->init = true;
- for (offset = 0; offset < sec->sh.sh_size; offset += insn->len) {
+ for (offset = 0; offset < sec_size(sec); offset += insn->len) {
if (!insns || idx == INSN_CHUNK_MAX) {
insns = calloc(INSN_CHUNK_SIZE, sizeof(*insn));
if (!insns) {
@@ -478,7 +478,7 @@ static int decode_instructions(struct objtool_file *file)
insn->offset = offset;
insn->prev_len = prev_len;
- if (arch_decode_instruction(file, sec, offset, sec->sh.sh_size - offset, insn))
+ if (arch_decode_instruction(file, sec, offset, sec_size(sec) - offset, insn))
return -1;
prev_len = insn->len;
@@ -496,12 +496,12 @@ static int decode_instructions(struct objtool_file *file)
}
sec_for_each_sym(sec, func) {
- if (func->type != STT_NOTYPE && func->type != STT_FUNC)
+ if (!is_notype_sym(func) && !is_func_sym(func))
continue;
- if (func->offset == sec->sh.sh_size) {
+ if (func->offset == sec_size(sec)) {
/* Heuristic: likely an "end" symbol */
- if (func->type == STT_NOTYPE)
+ if (is_notype_sym(func))
continue;
ERROR("%s(): STT_FUNC at end of section", func->name);
return -1;
@@ -517,7 +517,7 @@ static int decode_instructions(struct objtool_file *file)
sym_for_each_insn(file, func, insn) {
insn->sym = func;
- if (func->type == STT_FUNC &&
+ if (is_func_sym(func) &&
insn->type == INSN_ENDBR &&
list_empty(&insn->call_node)) {
if (insn->offset == func->offset) {
@@ -561,7 +561,7 @@ static int add_pv_ops(struct objtool_file *file, const char *symname)
idx = (reloc_offset(reloc) - sym->offset) / sizeof(unsigned long);
func = reloc->sym;
- if (func->type == STT_SECTION)
+ if (is_sec_sym(func))
func = find_symbol_by_offset(reloc->sym->sec,
reloc_addend(reloc));
if (!func) {
@@ -823,7 +823,7 @@ static int create_ibt_endbr_seal_sections(struct objtool_file *file)
struct symbol *sym = insn->sym;
*site = 0;
- if (opts.module && sym && sym->type == STT_FUNC &&
+ if (opts.module && sym && is_func_sym(sym) &&
insn->offset == sym->offset &&
(!strcmp(sym->name, "init_module") ||
!strcmp(sym->name, "cleanup_module"))) {
@@ -858,7 +858,7 @@ static int create_cfi_sections(struct objtool_file *file)
idx = 0;
for_each_sym(file->elf, sym) {
- if (sym->type != STT_FUNC)
+ if (!is_func_sym(sym))
continue;
if (strncmp(sym->name, "__cfi_", 6))
@@ -874,7 +874,7 @@ static int create_cfi_sections(struct objtool_file *file)
idx = 0;
for_each_sym(file->elf, sym) {
- if (sym->type != STT_FUNC)
+ if (!is_func_sym(sym))
continue;
if (strncmp(sym->name, "__cfi_", 6))
@@ -1463,7 +1463,7 @@ static bool jump_is_sibling_call(struct objtool_file *file,
return false;
/* Disallow sibling calls into STT_NOTYPE */
- if (ts->type == STT_NOTYPE)
+ if (is_notype_sym(ts))
return false;
/* Must not be self to be a sibling */
@@ -1497,7 +1497,7 @@ static int add_jump_destinations(struct objtool_file *file)
if (!reloc) {
dest_sec = insn->sec;
dest_off = arch_jump_destination(insn);
- } else if (reloc->sym->type == STT_SECTION) {
+ } else if (is_sec_sym(reloc->sym)) {
dest_sec = reloc->sym->sec;
dest_off = arch_insn_adjusted_addend(insn, reloc);
} else if (reloc->sym->retpoline_thunk) {
@@ -1657,12 +1657,12 @@ static int add_call_destinations(struct objtool_file *file)
return -1;
}
- if (func && insn_call_dest(insn)->type != STT_FUNC) {
+ if (func && !is_func_sym(insn_call_dest(insn))) {
ERROR_INSN(insn, "unsupported call to non-function");
return -1;
}
- } else if (reloc->sym->type == STT_SECTION) {
+ } else if (is_sec_sym(reloc->sym)) {
dest_off = arch_insn_adjusted_addend(insn, reloc);
dest = find_call_destination(reloc->sym->sec, dest_off);
if (!dest) {
@@ -2146,7 +2146,7 @@ static int add_jump_table_alts(struct objtool_file *file)
return 0;
for_each_sym(file->elf, func) {
- if (func->type != STT_FUNC)
+ if (!is_func_sym(func))
continue;
mark_func_jump_tables(file, func);
@@ -2185,14 +2185,14 @@ static int read_unwind_hints(struct objtool_file *file)
return -1;
}
- if (sec->sh.sh_size % sizeof(struct unwind_hint)) {
+ if (sec_size(sec) % sizeof(struct unwind_hint)) {
ERROR("struct unwind_hint size mismatch");
return -1;
}
file->hints = true;
- for (i = 0; i < sec->sh.sh_size / sizeof(struct unwind_hint); i++) {
+ for (i = 0; i < sec_size(sec) / sizeof(struct unwind_hint); i++) {
hint = (struct unwind_hint *)sec->data->d_buf + i;
reloc = find_reloc_by_dest(file->elf, sec, i * sizeof(*hint));
@@ -2201,7 +2201,7 @@ static int read_unwind_hints(struct objtool_file *file)
return -1;
}
- if (reloc->sym->type == STT_SECTION) {
+ if (is_sec_sym(reloc->sym)) {
offset = reloc_addend(reloc);
} else if (reloc->sym->local_label) {
offset = reloc->sym->offset;
@@ -2237,7 +2237,7 @@ static int read_unwind_hints(struct objtool_file *file)
if (hint->type == UNWIND_HINT_TYPE_REGS_PARTIAL) {
struct symbol *sym = find_symbol_by_offset(insn->sec, insn->offset);
- if (sym && sym->bind == STB_GLOBAL) {
+ if (sym && is_global_sym(sym)) {
if (opts.ibt && insn->type != INSN_ENDBR && !insn->noendbr) {
ERROR_INSN(insn, "UNWIND_HINT_IRET_REGS without ENDBR");
return -1;
@@ -2452,10 +2452,10 @@ static int classify_symbols(struct objtool_file *file)
struct symbol *func;
for_each_sym(file->elf, func) {
- if (func->type == STT_NOTYPE && strstarts(func->name, ".L"))
+ if (is_notype_sym(func) && strstarts(func->name, ".L"))
func->local_label = true;
- if (func->bind != STB_GLOBAL)
+ if (!is_global_sym(func))
continue;
if (!strncmp(func->name, STATIC_CALL_TRAMP_PREFIX_STR,
@@ -4179,11 +4179,11 @@ static int add_prefix_symbols(struct objtool_file *file)
struct symbol *func;
for_each_sec(file->elf, sec) {
- if (!(sec->sh.sh_flags & SHF_EXECINSTR))
+ if (!is_text_sec(sec))
continue;
sec_for_each_sym(sec, func) {
- if (func->type != STT_FUNC)
+ if (!is_func_sym(func))
continue;
add_prefix_symbol(file, func);
@@ -4227,7 +4227,7 @@ static int validate_section(struct objtool_file *file, struct section *sec)
int warnings = 0;
sec_for_each_sym(sec, func) {
- if (func->type != STT_FUNC)
+ if (!is_func_sym(func))
continue;
init_insn_state(file, &state, sec);
@@ -4271,7 +4271,7 @@ static int validate_functions(struct objtool_file *file)
int warnings = 0;
for_each_sec(file->elf, sec) {
- if (!(sec->sh.sh_flags & SHF_EXECINSTR))
+ if (!is_text_sec(sec))
continue;
warnings += validate_section(file, sec);
@@ -4452,7 +4452,7 @@ static int validate_ibt(struct objtool_file *file)
for_each_sec(file->elf, sec) {
/* Already done by validate_ibt_insn() */
- if (sec->sh.sh_flags & SHF_EXECINSTR)
+ if (is_text_sec(sec))
continue;
if (!sec->rsec)