[v2,9/9] objtool: Ignore exc_double_fault() __noreturn warnings

Message ID 683214828d8b2ad732dab1a74e858087519d8c8b.1681325924.git.jpoimboe@kernel.org
State New
Headers
Series objtool: warning improvements |

Commit Message

Josh Poimboeuf April 12, 2023, 7:03 p.m. UTC
  This is a hack, but it works for now.

Problem is, exc_double_fault() may or may not return, depending on
whether CONFIG_X86_ESPFIX64 is set.  But objtool has no visibility to
the kernel config.

"Fix" it by silencing the exc_double_fault() __noreturn warning.

This removes the following warning:

  vmlinux.o: warning: objtool: xenpv_exc_double_fault+0xd: exc_double_fault() is missing a __noreturn annotation

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

Comments

Peter Zijlstra April 13, 2023, 9:24 a.m. UTC | #1
On Wed, Apr 12, 2023 at 12:03:24PM -0700, Josh Poimboeuf wrote:
> +	 *   - have compiler communicate __noreturn functions somehow

This, we're going to have to do that -- because keeping that (ever
growing) list in sync is going to be a pain in the backside.
  
Nick Desaulniers April 14, 2023, 9:16 p.m. UTC | #2
On Thu, Apr 13, 2023 at 2:24 AM Peter Zijlstra <peterz@infradead.org> wrote:
>
> On Wed, Apr 12, 2023 at 12:03:24PM -0700, Josh Poimboeuf wrote:
> > +      *   - have compiler communicate __noreturn functions somehow

Could probably stuff these in some kind of "noreturn function symbol
table"/custom elf section; DWARF tags are nice but we don't always
want debug info.  (I should ask colleagues if there's anything like
this in DWARF already, perhaps for DWARFv6).

>
> This, we're going to have to do that -- because keeping that (ever
> growing) list in sync is going to be a pain in the backside.
>
  

Patch

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 60f2d649f19f..7641e818db7d 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -4483,6 +4483,35 @@  static int validate_sls(struct objtool_file *file)
 	return warnings;
 }
 
+static bool ignore_noreturn_call(struct instruction *insn)
+{
+	struct symbol *call_dest = insn_call_dest(insn);
+
+	/*
+	 * This is a hack, but it works for now.
+	 *
+	 * Problem is, exc_double_fault() may or may not return, depending on
+	 * whether CONFIG_X86_ESPFIX64 is set.  But objtool has no visibility
+	 * to the kernel config.
+	 *
+	 * Other potential ways to fix it:
+	 *
+	 *   - remove CONFIG_X86_ESPFIX64
+	 *   - read the .config file
+	 *   - add a cmdline option
+	 *   - create a generic objtool annotation format (vs a bunch of custom
+	 *     formats) and annotate it
+	 *   - have compiler communicate __noreturn functions somehow
+	 */
+	if (!strcmp(call_dest->name, "exc_double_fault")) {
+		/* prevent further unreachable warnings for the caller */
+		insn->sym->warned = 1;
+		return true;
+	}
+
+	return false;
+}
+
 static int validate_reachable_instructions(struct objtool_file *file)
 {
 	struct instruction *insn, *prev_insn;
@@ -4499,7 +4528,7 @@  static int validate_reachable_instructions(struct objtool_file *file)
 		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) {
+			if (call_dest && !ignore_noreturn_call(prev_insn)) {
 				WARN_INSN(insn, "%s() is missing a __noreturn annotation",
 					  call_dest->name);
 				warnings++;