lkml.org 
[lkml]   [2016]   [May]   [13]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH] objtool: cope with pre-4.5 gcc (and non-gcc)
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;



\
 
 \ /
  Last update: 2016-05-13 08:41    [W:0.040 / U:0.148 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site