objtool: Improve rate-limiting for missing __noreturn warnings

Message ID 185b1a78b42776467929ce9e7851e4dbcd0b55d4.1686241345.git.jpoimboe@kernel.org
State New
Headers
Series objtool: Improve rate-limiting for missing __noreturn warnings |

Commit Message

Josh Poimboeuf June 8, 2023, 4:23 p.m. UTC
  If a function with a lot of call sites is missing __noreturn, it could
result in a lot of duplicate warnings (one for each call site).

Each call site's function is already rate-limited to one warning per
function via WARN_INSN().  Do the same for the callee (the "missing
__noreturn" function itself).

Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
---
 tools/objtool/check.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
  

Comments

Josh Poimboeuf June 8, 2023, 8:54 p.m. UTC | #1
On Thu, Jun 08, 2023 at 09:23:32AM -0700, Josh Poimboeuf wrote:
> If a function with a lot of call sites is missing __noreturn, it could
> result in a lot of duplicate warnings (one for each call site).
> 
> Each call site's function is already rate-limited to one warning per
> function via WARN_INSN().  Do the same for the callee (the "missing
> __noreturn" function itself).
> 
> Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
> ---
>  tools/objtool/check.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/objtool/check.c b/tools/objtool/check.c
> index 8936a05f0e5a..bb2ed34cb90e 100644
> --- a/tools/objtool/check.c
> +++ b/tools/objtool/check.c
> @@ -4507,9 +4507,13 @@ static int validate_reachable_instructions(struct objtool_file *file)
>  		if (prev_insn && prev_insn->dead_end) {
>  			call_dest = insn_call_dest(prev_insn);
>  			if (call_dest && !ignore_noreturn_call(prev_insn)) {
> -				WARN_INSN(insn, "%s() is missing a __noreturn annotation",
> -					  call_dest->name);
> -				warnings++;
> +				if (!call_dest->warned) {
> +					WARN_INSN(insn, "%s() is missing a __noreturn annotation",
> +						  call_dest->name);
> +					warnings++;
> +					call_dest->warned = 1;
> +				}
> +

NAK - this spits out a bunch of unreachables, will need to tweak it a
bit.
  

Patch

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 8936a05f0e5a..bb2ed34cb90e 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -4507,9 +4507,13 @@  static int validate_reachable_instructions(struct objtool_file *file)
 		if (prev_insn && prev_insn->dead_end) {
 			call_dest = insn_call_dest(prev_insn);
 			if (call_dest && !ignore_noreturn_call(prev_insn)) {
-				WARN_INSN(insn, "%s() is missing a __noreturn annotation",
-					  call_dest->name);
-				warnings++;
+				if (!call_dest->warned) {
+					WARN_INSN(insn, "%s() is missing a __noreturn annotation",
+						  call_dest->name);
+					warnings++;
+					call_dest->warned = 1;
+				}
+
 				continue;
 			}
 		}