Skip to content

Commit 9cfffb1

Browse files
jpoimboeIngo Molnar
authored andcommitted
objtool: Skip all "unreachable instruction" warnings for gcov kernels
Recently objtool has started reporting a few "unreachable instruction" warnings when CONFIG_GCOV is enabled for newer versions of GCC. Usually this warning means there's some new control flow that objtool doesn't understand. But in this case, objtool is correct and the instructions really are inaccessible. It's an annoying quirk of gcov, but it's harmless, so it's ok to just silence the warnings. With older versions of GCC, it was relatively easy to detect gcov-specific instructions and to skip any unreachable warnings produced by them. But GCC 6 has gotten craftier. Instead of continuing to play whack-a-mole with gcov, just use a bigger, more permanent hammer and disable unreachable warnings for the whole file when gcov is enabled. This is fine to do because a) unreachable warnings are usually of questionable value; and b) gcov isn't used for production kernels and we can relax the checks a bit there. Reported-by: kbuild test robot <fengguang.wu@intel.com> Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Andy Lutomirski <luto@kernel.org> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Borislav Petkov <bp@alien8.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/38d5c87d61d9cd46486dd2c86f46603dff0df86f.1476393584.git.jpoimboe@redhat.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 3732710 commit 9cfffb1

File tree

1 file changed

+26
-31
lines changed

1 file changed

+26
-31
lines changed

tools/objtool/builtin-check.c

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,19 @@ static struct instruction *next_insn_same_sec(struct objtool_file *file,
9797
return next;
9898
}
9999

100+
static bool gcov_enabled(struct objtool_file *file)
101+
{
102+
struct section *sec;
103+
struct symbol *sym;
104+
105+
list_for_each_entry(sec, &file->elf->sections, list)
106+
list_for_each_entry(sym, &sec->symbol_list, list)
107+
if (!strncmp(sym->name, "__gcov_.", 8))
108+
return true;
109+
110+
return false;
111+
}
112+
100113
#define for_each_insn(file, insn) \
101114
list_for_each_entry(insn, &file->insn_list, list)
102115

@@ -1041,34 +1054,6 @@ static int validate_branch(struct objtool_file *file,
10411054
return 0;
10421055
}
10431056

1044-
static bool is_gcov_insn(struct instruction *insn)
1045-
{
1046-
struct rela *rela;
1047-
struct section *sec;
1048-
struct symbol *sym;
1049-
unsigned long offset;
1050-
1051-
rela = find_rela_by_dest_range(insn->sec, insn->offset, insn->len);
1052-
if (!rela)
1053-
return false;
1054-
1055-
if (rela->sym->type != STT_SECTION)
1056-
return false;
1057-
1058-
sec = rela->sym->sec;
1059-
offset = rela->addend + insn->offset + insn->len - rela->offset;
1060-
1061-
list_for_each_entry(sym, &sec->symbol_list, list) {
1062-
if (sym->type != STT_OBJECT)
1063-
continue;
1064-
1065-
if (offset >= sym->offset && offset < sym->offset + sym->len)
1066-
return (!memcmp(sym->name, "__gcov0.", 8));
1067-
}
1068-
1069-
return false;
1070-
}
1071-
10721057
static bool is_kasan_insn(struct instruction *insn)
10731058
{
10741059
return (insn->type == INSN_CALL &&
@@ -1090,9 +1075,6 @@ static bool ignore_unreachable_insn(struct symbol *func,
10901075
if (insn->type == INSN_NOP)
10911076
return true;
10921077

1093-
if (is_gcov_insn(insn))
1094-
return true;
1095-
10961078
/*
10971079
* Check if this (or a subsequent) instruction is related to
10981080
* CONFIG_UBSAN or CONFIG_KASAN.
@@ -1153,6 +1135,19 @@ static int validate_functions(struct objtool_file *file)
11531135
ignore_unreachable_insn(func, insn))
11541136
continue;
11551137

1138+
/*
1139+
* gcov produces a lot of unreachable
1140+
* instructions. If we get an unreachable
1141+
* warning and the file has gcov enabled, just
1142+
* ignore it, and all other such warnings for
1143+
* the file.
1144+
*/
1145+
if (!file->ignore_unreachables &&
1146+
gcov_enabled(file)) {
1147+
file->ignore_unreachables = true;
1148+
continue;
1149+
}
1150+
11561151
WARN_FUNC("function has unreachable instruction", insn->sec, insn->offset);
11571152
warnings++;
11581153
}

0 commit comments

Comments
 (0)