objtool: Detect missing __noreturn annotations
authorJosh Poimboeuf <jpoimboe@kernel.org>
Tue, 18 Apr 2023 21:27:50 +0000 (14:27 -0700)
committerJosh Poimboeuf <jpoimboe@kernel.org>
Tue, 16 May 2023 13:31:53 +0000 (06:31 -0700)
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>
tools/objtool/Documentation/objtool.txt
tools/objtool/check.c

index 9ec8cbf20668b146ace6cac69a6827474df3bffd..f9345e0ce74016a0e77a8fa8fef52b2cc2e1f58e 100644 (file)
@@ -303,6 +303,12 @@ the objtool maintainers.
    If it's not actually in a callable function (e.g. kernel entry code),
    change ENDPROC to END.
 
+3. file.o: warning: objtool: foo+0x48c: bar() is missing a __noreturn annotation
+
+   The call from foo() to bar() doesn't return, but bar() 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.
 
 4. file.o: warning: objtool: func(): can't find starting instruction
    or
index 71985f3a6fa64659126327b271eedbbdd6c8ce64..8d1b4226608c574798df027cbeecab13fabde413 100644 (file)
@@ -4507,7 +4507,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;
        int warnings = 0;
 
        if (file->ignore_unreachables)
@@ -4517,6 +4518,17 @@ static int validate_reachable_instructions(struct objtool_file *file)
                if (insn->visited || ignore_unreachable_insn(file, insn))
                        continue;
 
+               prev_insn = prev_insn_same_sec(file, insn);
+               if (prev_insn && prev_insn->dead_end) {
+                       call_dest = insn_call_dest(prev_insn);
+                       if (call_dest) {
+                               WARN_INSN(insn, "%s() is missing a __noreturn annotation",
+                                         call_dest->name);
+                               warnings++;
+                               continue;
+                       }
+               }
+
                WARN_INSN(insn, "unreachable instruction");
                warnings++;
        }