* [PATCH] objtool: cope with pre-4.5 gcc (and non-gcc)
@ 2016-05-13 6:27 Jan Beulich
2016-05-16 21:40 ` Josh Poimboeuf
0 siblings, 1 reply; 2+ messages in thread
From: Jan Beulich @ 2016-05-13 6:27 UTC (permalink / raw)
To: Josh Poimboeuf; +Cc: linux-kernel
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;
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] objtool: cope with pre-4.5 gcc (and non-gcc)
2016-05-13 6:27 [PATCH] objtool: cope with pre-4.5 gcc (and non-gcc) Jan Beulich
@ 2016-05-16 21:40 ` Josh Poimboeuf
0 siblings, 0 replies; 2+ messages in thread
From: Josh Poimboeuf @ 2016-05-16 21:40 UTC (permalink / raw)
To: Jan Beulich; +Cc: linux-kernel
On Fri, May 13, 2016 at 12:27:06AM -0600, Jan Beulich wrote:
> 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>
Thanks for the patch. I'm wondering if we can detect this situation
more precisely, maybe by adding some kind of annotation to the
unreachable() macro. Will need to think about it a little more...
--
Josh
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-05-16 21:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-13 6:27 [PATCH] objtool: cope with pre-4.5 gcc (and non-gcc) Jan Beulich
2016-05-16 21:40 ` Josh Poimboeuf
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®