objtool: Ignore entire functions rather than instructions

STACK_FRAME_NON_STANDARD applies to functions.  Use a function-specific
ignore attribute in preparation for getting rid of insn->ignore.

Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/4af13376567f83331a9372ae2bb25e11a3d0f055.1742852846.git.jpoimboe@kernel.org
This commit is contained in:
Josh Poimboeuf 2025-03-24 14:55:53 -07:00 committed by Ingo Molnar
parent eeff7ac615
commit c84301d706
2 changed files with 19 additions and 17 deletions

View file

@ -981,7 +981,6 @@ static int create_direct_call_sections(struct objtool_file *file)
*/ */
static void add_ignores(struct objtool_file *file) static void add_ignores(struct objtool_file *file)
{ {
struct instruction *insn;
struct section *rsec; struct section *rsec;
struct symbol *func; struct symbol *func;
struct reloc *reloc; struct reloc *reloc;
@ -1008,8 +1007,7 @@ static void add_ignores(struct objtool_file *file)
continue; continue;
} }
func_for_each_insn(file, func, insn) func->ignore = true;
insn->ignore = true;
} }
} }
@ -1612,6 +1610,7 @@ static int add_call_destinations(struct objtool_file *file)
struct reloc *reloc; struct reloc *reloc;
for_each_insn(file, insn) { for_each_insn(file, insn) {
struct symbol *func = insn_func(insn);
if (insn->type != INSN_CALL) if (insn->type != INSN_CALL)
continue; continue;
@ -1622,7 +1621,7 @@ static int add_call_destinations(struct objtool_file *file)
add_call_dest(file, insn, dest, false); add_call_dest(file, insn, dest, false);
if (insn->ignore) if (func && func->ignore)
continue; continue;
if (!insn_call_dest(insn)) { if (!insn_call_dest(insn)) {
@ -1630,7 +1629,7 @@ static int add_call_destinations(struct objtool_file *file)
return -1; return -1;
} }
if (insn_func(insn) && insn_call_dest(insn)->type != STT_FUNC) { if (func && insn_call_dest(insn)->type != STT_FUNC) {
WARN_INSN(insn, "unsupported call to non-function"); WARN_INSN(insn, "unsupported call to non-function");
return -1; return -1;
} }
@ -3470,6 +3469,9 @@ static int validate_branch(struct objtool_file *file, struct symbol *func,
u8 visited; u8 visited;
int ret; int ret;
if (func && func->ignore)
return 0;
sec = insn->sec; sec = insn->sec;
while (1) { while (1) {
@ -3715,7 +3717,7 @@ static int validate_unwind_hint(struct objtool_file *file,
struct instruction *insn, struct instruction *insn,
struct insn_state *state) struct insn_state *state)
{ {
if (insn->hint && !insn->visited && !insn->ignore) { if (insn->hint && !insn->visited) {
int ret = validate_branch(file, insn_func(insn), insn, *state); int ret = validate_branch(file, insn_func(insn), insn, *state);
if (ret) if (ret)
BT_INSN(insn, "<=== (hint)"); BT_INSN(insn, "<=== (hint)");
@ -3929,10 +3931,11 @@ static bool is_ubsan_insn(struct instruction *insn)
static bool ignore_unreachable_insn(struct objtool_file *file, struct instruction *insn) static bool ignore_unreachable_insn(struct objtool_file *file, struct instruction *insn)
{ {
int i; struct symbol *func = insn_func(insn);
struct instruction *prev_insn; struct instruction *prev_insn;
int i;
if (insn->ignore || insn->type == INSN_NOP || insn->type == INSN_TRAP) if (insn->ignore || insn->type == INSN_NOP || insn->type == INSN_TRAP || (func && func->ignore))
return true; return true;
/* /*
@ -3951,7 +3954,7 @@ static bool ignore_unreachable_insn(struct objtool_file *file, struct instructio
* In this case we'll find a piece of code (whole function) that is not * In this case we'll find a piece of code (whole function) that is not
* covered by a !section symbol. Ignore them. * covered by a !section symbol. Ignore them.
*/ */
if (opts.link && !insn_func(insn)) { if (opts.link && !func) {
int size = find_symbol_hole_containing(insn->sec, insn->offset); int size = find_symbol_hole_containing(insn->sec, insn->offset);
unsigned long end = insn->offset + size; unsigned long end = insn->offset + size;
@ -3977,19 +3980,17 @@ static bool ignore_unreachable_insn(struct objtool_file *file, struct instructio
*/ */
if (insn->jump_dest && insn_func(insn->jump_dest) && if (insn->jump_dest && insn_func(insn->jump_dest) &&
strstr(insn_func(insn->jump_dest)->name, ".cold")) { strstr(insn_func(insn->jump_dest)->name, ".cold")) {
struct instruction *dest = insn->jump_dest; insn_func(insn->jump_dest)->ignore = true;
func_for_each_insn(file, insn_func(dest), dest)
dest->ignore = true;
} }
} }
return false; return false;
} }
if (!insn_func(insn)) if (!func)
return false; return false;
if (insn_func(insn)->static_call_tramp) if (func->static_call_tramp)
return true; return true;
/* /*
@ -4020,7 +4021,7 @@ static bool ignore_unreachable_insn(struct objtool_file *file, struct instructio
if (insn->type == INSN_JUMP_UNCONDITIONAL) { if (insn->type == INSN_JUMP_UNCONDITIONAL) {
if (insn->jump_dest && if (insn->jump_dest &&
insn_func(insn->jump_dest) == insn_func(insn)) { insn_func(insn->jump_dest) == func) {
insn = insn->jump_dest; insn = insn->jump_dest;
continue; continue;
} }
@ -4028,7 +4029,7 @@ static bool ignore_unreachable_insn(struct objtool_file *file, struct instructio
break; break;
} }
if (insn->offset + insn->len >= insn_func(insn)->offset + insn_func(insn)->len) if (insn->offset + insn->len >= func->offset + func->len)
break; break;
insn = next_insn_same_sec(file, insn); insn = next_insn_same_sec(file, insn);
@ -4120,7 +4121,7 @@ static int validate_symbol(struct objtool_file *file, struct section *sec,
return 0; return 0;
insn = find_insn(file, sec, sym->offset); insn = find_insn(file, sec, sym->offset);
if (!insn || insn->ignore || insn->visited) if (!insn || insn->visited)
return 0; return 0;
state->uaccess = sym->uaccess_safe; state->uaccess = sym->uaccess_safe;

View file

@ -68,6 +68,7 @@ struct symbol {
u8 embedded_insn : 1; u8 embedded_insn : 1;
u8 local_label : 1; u8 local_label : 1;
u8 frame_pointer : 1; u8 frame_pointer : 1;
u8 ignore : 1;
u8 warnings : 2; u8 warnings : 2;
struct list_head pv_target; struct list_head pv_target;
struct reloc *relocs; struct reloc *relocs;