mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Jan Beulich" <JBeulich@suse.com>
To: "Josh Poimboeuf" <jpoimboe@redhat.com>
Cc: <linux-kernel@vger.kernel.org>
Subject: [PATCH] objtool: cope with pre-4.5 gcc (and non-gcc)
Date: Fri, 13 May 2016 00:27:06 -0600	[thread overview]
Message-ID: <57358FDA02000078000EB174@prv-mh.provo.novell.com> (raw)

The kernel's unreachable() translates to __builtin_unreachable() only
for gcc 4.5 and newer, and else expands to an infinite loop. Avoid
"function has unreachable instruction" warnings for this case by
inspecting the instructions immediately following the UD2. This cuts
down the number of files getting such warnings by about 99% for me.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
---
 tools/objtool/builtin-check.c |   37 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

--- 4.6-rc7/tools/objtool/builtin-check.c
+++ 4.6-rc7-objtool-BUG-older-gcc/tools/objtool/builtin-check.c
@@ -1033,6 +1033,39 @@ static bool is_ubsan_insn(struct instruc
 			"__ubsan_handle_builtin_unreachable"));
 }
 
+/*
+ * BUG() uses unreachable(), which on older gcc translates to an infinite
+ * loop, i.e. a branch targeting itself (or a group of immediately preceding
+ * NOPs). Avoid that branch (and the NOPs) getting considered unreachable,
+ * despite it really being so.
+ */
+static void mark_post_bug_insns(struct objtool_file *file,
+				struct instruction *insn)
+{
+	const struct instruction *first_nop = NULL;
+
+	if (insn->type != INSN_BUG)
+		return;
+
+	while ((insn = next_insn_same_sec(file, insn)) != NULL) {
+		switch (insn->type) {
+		case INSN_NOP:
+			insn->visited = true;
+			if (!first_nop)
+				first_nop = insn;
+			continue;
+		case INSN_JUMP_UNCONDITIONAL:
+			if (insn->jump_dest == insn ||
+			    (first_nop && insn->jump_dest == first_nop))
+				insn->visited = true;
+			break;
+		default:
+			break;
+		}
+		break;
+	}
+}
+
 static bool ignore_unreachable_insn(struct symbol *func,
 				    struct instruction *insn)
 {
@@ -1095,8 +1128,10 @@ static int validate_functions(struct obj
 				continue;
 
 			func_for_each_insn(file, func, insn) {
-				if (insn->visited)
+				if (insn->visited) {
+					mark_post_bug_insns(file, insn);
 					continue;
+				}
 
 				insn->visited = true;
 

             reply	other threads:[~2016-05-13  6:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-13  6:27 Jan Beulich [this message]
2016-05-16 21:40 ` Josh Poimboeuf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=57358FDA02000078000EB174@prv-mh.provo.novell.com \
    --to=jbeulich@suse.com \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®