Commit 9cfffb11 authored by Josh Poimboeuf's avatar Josh Poimboeuf Committed by Ingo Molnar

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: default avatarkbuild test robot <>
Signed-off-by: default avatarJosh Poimboeuf <>
Cc: Andy Lutomirski <>
Cc: Arnd Bergmann <>
Cc: Borislav Petkov <>
Cc: Brian Gerst <>
Cc: Denys Vlasenko <>
Cc: H. Peter Anvin <>
Cc: Linus Torvalds <>
Cc: Peter Zijlstra <>
Cc: Thomas Gleixner <>
Link: default avatarIngo Molnar <>
parent 3732710f
......@@ -97,6 +97,19 @@ static struct instruction *next_insn_same_sec(struct objtool_file *file,
return next;
static bool gcov_enabled(struct objtool_file *file)
struct section *sec;
struct symbol *sym;
list_for_each_entry(sec, &file->elf->sections, list)
list_for_each_entry(sym, &sec->symbol_list, list)
if (!strncmp(sym->name, "__gcov_.", 8))
return true;
return false;
#define for_each_insn(file, insn) \
list_for_each_entry(insn, &file->insn_list, list)
......@@ -1041,34 +1054,6 @@ static int validate_branch(struct objtool_file *file,
return 0;
static bool is_gcov_insn(struct instruction *insn)
struct rela *rela;
struct section *sec;
struct symbol *sym;
unsigned long offset;
rela = find_rela_by_dest_range(insn->sec, insn->offset, insn->len);
if (!rela)
return false;
if (rela->sym->type != STT_SECTION)
return false;
sec = rela->sym->sec;
offset = rela->addend + insn->offset + insn->len - rela->offset;
list_for_each_entry(sym, &sec->symbol_list, list) {
if (sym->type != STT_OBJECT)
if (offset >= sym->offset && offset < sym->offset + sym->len)
return (!memcmp(sym->name, "__gcov0.", 8));
return false;
static bool is_kasan_insn(struct instruction *insn)
return (insn->type == INSN_CALL &&
......@@ -1090,9 +1075,6 @@ static bool ignore_unreachable_insn(struct symbol *func,
if (insn->type == INSN_NOP)
return true;
if (is_gcov_insn(insn))
return true;
* Check if this (or a subsequent) instruction is related to
......@@ -1153,6 +1135,19 @@ static int validate_functions(struct objtool_file *file)
ignore_unreachable_insn(func, insn))
* gcov produces a lot of unreachable
* instructions. If we get an unreachable
* warning and the file has gcov enabled, just
* ignore it, and all other such warnings for
* the file.
if (!file->ignore_unreachables &&
gcov_enabled(file)) {
file->ignore_unreachables = true;
WARN_FUNC("function has unreachable instruction", insn->sec, insn->offset);
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment