[5/5] objtool: Add "missing __noreturn" warning
Commit Message
Most "unreachable instruction" warnings these days seem to actually be
the result of a missing __noreturn annotation. Add an explicit check
for that.
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
---
tools/objtool/Documentation/objtool.txt | 7 +++++++
tools/objtool/check.c | 16 ++++++++++++++--
2 files changed, 21 insertions(+), 2 deletions(-)
Comments
> WARN_FUNC("unreachable instruction", insn->sec, insn->offset);
> - return 1;
I knew I should have read the whole set first...
Miroslav
On Tue, Mar 28, 2023 at 11:10:48AM +0200, Miroslav Benes wrote:
> > WARN_FUNC("unreachable instruction", insn->sec, insn->offset);
> > - return 1;
>
> I knew I should have read the whole set first...
Oops, guess that is in the wrong patch.
@@ -423,6 +423,13 @@ the objtool maintainers.
names and does not use module_init() / module_exit() macros to create
them.
+13. file.o: warning: func(): missing __noreturn
+
+ Objtool has detected that the function doesn't return, but is missing
+ the __noreturn annotation. NOTE: In addition to adding the
+ __noreturn annotation, the function name also needs to be added to
+ 'global_noreturns' in tools/objtool/check.c.
+
If the error doesn't seem to make sense, it could be a bug in objtool.
Feel free to ask the objtool maintainer for help.
@@ -4548,7 +4548,8 @@ static int validate_sls(struct objtool_file *file)
static int validate_reachable_instructions(struct objtool_file *file)
{
- struct instruction *insn;
+ struct instruction *insn, *prev_insn;
+ struct symbol *call_dest;
if (file->ignore_unreachables)
return 0;
@@ -4561,8 +4562,19 @@ static int validate_reachable_instructions(struct objtool_file *file)
continue;
insn->sym->warned = 1;
+ prev_insn = prev_insn_same_sec(file, insn);
+ if (prev_insn)
+ call_dest = insn_call_dest(prev_insn);
+ if (prev_insn && prev_insn->dead_end && call_dest) {
+ if (call_dest->warned)
+ continue;
+ call_dest->warned = 1;
+
+ WARN("%s(): missing __noreturn", call_dest->name);
+ continue;
+ }
+
WARN_FUNC("unreachable instruction", insn->sec, insn->offset);
- return 1;
}
return 0;