Skip to content

Commit fedb724

Browse files
committed
objtool: Detect missing __noreturn annotations
Most "unreachable instruction" warnings these days seem to actually be the result of a missing __noreturn annotation. Add an explicit check for that. Reviewed-by: Miroslav Benes <mbenes@suse.cz> Link: https://lore.kernel.org/r/6e2b93d8c65eaed6c4166a358269dc0ef01f890c.1681853186.git.jpoimboe@kernel.org Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
1 parent ced23d2 commit fedb724

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

tools/objtool/Documentation/objtool.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,12 @@ the objtool maintainers.
303303
If it's not actually in a callable function (e.g. kernel entry code),
304304
change ENDPROC to END.
305305

306+
3. file.o: warning: objtool: foo+0x48c: bar() is missing a __noreturn annotation
307+
308+
The call from foo() to bar() doesn't return, but bar() is missing the
309+
__noreturn annotation. NOTE: In addition to adding the __noreturn
310+
annotation, the function name also needs to be added to
311+
'global_noreturns' in tools/objtool/check.c.
306312

307313
4. file.o: warning: objtool: func(): can't find starting instruction
308314
or

tools/objtool/check.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4507,7 +4507,8 @@ static int validate_sls(struct objtool_file *file)
45074507

45084508
static int validate_reachable_instructions(struct objtool_file *file)
45094509
{
4510-
struct instruction *insn;
4510+
struct instruction *insn, *prev_insn;
4511+
struct symbol *call_dest;
45114512
int warnings = 0;
45124513

45134514
if (file->ignore_unreachables)
@@ -4517,6 +4518,17 @@ static int validate_reachable_instructions(struct objtool_file *file)
45174518
if (insn->visited || ignore_unreachable_insn(file, insn))
45184519
continue;
45194520

4521+
prev_insn = prev_insn_same_sec(file, insn);
4522+
if (prev_insn && prev_insn->dead_end) {
4523+
call_dest = insn_call_dest(prev_insn);
4524+
if (call_dest) {
4525+
WARN_INSN(insn, "%s() is missing a __noreturn annotation",
4526+
call_dest->name);
4527+
warnings++;
4528+
continue;
4529+
}
4530+
}
4531+
45204532
WARN_INSN(insn, "unreachable instruction");
45214533
warnings++;
45224534
}

0 commit comments

Comments
 (0)