Skip to content

Commit 867ac9d

Browse files
jpoimboeIngo Molnar
authored andcommitted
objtool: Fix gcov check for older versions of GCC
Objtool tries to silence 'unreachable instruction' warnings when it detects gcov is enabled, because gcov produces a lot of unreachable instructions and they don't really matter. However, the 0-day bot is still reporting some unreachable instruction warnings with CONFIG_GCOV_KERNEL=y on GCC 4.6.4. As it turns out, objtool's gcov detection doesn't work with older versions of GCC because they don't create a bunch of symbols with the 'gcov.' prefix like newer versions of GCC do. Move the gcov check out of objtool and instead just create a new '--no-unreachable' flag which can be passed in by the kernel Makefile when CONFIG_GCOV_KERNEL is defined. Also rename the 'nofp' variable to 'no_fp' for consistency with the new 'no_unreachable' variable. Reported-by: kbuild test robot <fengguang.wu@intel.com> Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Fixes: 9cfffb1 ("objtool: Skip all "unreachable instruction" warnings for gcov kernels") Link: http://lkml.kernel.org/r/c243dc78eb2ffdabb6e927844dea39b6033cd395.1500939244.git.jpoimboe@redhat.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 9683a64 commit 867ac9d

File tree

5 files changed

+17
-35
lines changed

5 files changed

+17
-35
lines changed

scripts/Makefile.build

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@ objtool_args = check
262262
ifndef CONFIG_FRAME_POINTER
263263
objtool_args += --no-fp
264264
endif
265+
ifdef CONFIG_GCOV_KERNEL
266+
objtool_args += --no-unreachable
267+
endif
265268

266269
# 'OBJECT_FILES_NON_STANDARD := y': skip objtool checking for a directory
267270
# 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file

tools/objtool/builtin-check.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,16 @@
2929
#include "builtin.h"
3030
#include "check.h"
3131

32-
bool nofp;
32+
bool no_fp, no_unreachable;
3333

3434
static const char * const check_usage[] = {
3535
"objtool check [<options>] file.o",
3636
NULL,
3737
};
3838

3939
const struct option check_options[] = {
40-
OPT_BOOLEAN('f', "no-fp", &nofp, "Skip frame pointer validation"),
40+
OPT_BOOLEAN('f', "no-fp", &no_fp, "Skip frame pointer validation"),
41+
OPT_BOOLEAN('u', "no-unreachable", &no_unreachable, "Skip 'unreachable instruction' warnings"),
4142
OPT_END(),
4243
};
4344

@@ -52,5 +53,5 @@ int cmd_check(int argc, const char **argv)
5253

5354
objname = argv[0];
5455

55-
return check(objname, nofp, false);
56+
return check(objname, no_fp, no_unreachable, false);
5657
}

tools/objtool/builtin-orc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static const char *orc_usage[] = {
3737
};
3838

3939
extern const struct option check_options[];
40-
extern bool nofp;
40+
extern bool no_fp, no_unreachable;
4141

4242
int cmd_orc(int argc, const char **argv)
4343
{
@@ -51,7 +51,7 @@ int cmd_orc(int argc, const char **argv)
5151

5252
objname = argv[0];
5353

54-
return check(objname, nofp, true);
54+
return check(objname, no_fp, no_unreachable, true);
5555

5656
}
5757

tools/objtool/check.c

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct alternative {
3333
};
3434

3535
const char *objname;
36-
static bool nofp;
36+
static bool no_fp;
3737
struct cfi_state initial_func_cfi;
3838

3939
struct instruction *find_insn(struct objtool_file *file,
@@ -59,19 +59,6 @@ static struct instruction *next_insn_same_sec(struct objtool_file *file,
5959
return next;
6060
}
6161

62-
static bool gcov_enabled(struct objtool_file *file)
63-
{
64-
struct section *sec;
65-
struct symbol *sym;
66-
67-
for_each_sec(file, sec)
68-
list_for_each_entry(sym, &sec->symbol_list, list)
69-
if (!strncmp(sym->name, "__gcov_.", 8))
70-
return true;
71-
72-
return false;
73-
}
74-
7562
#define func_for_each_insn(file, func, insn) \
7663
for (insn = find_insn(file, func->sec, func->offset); \
7764
insn && &insn->list != &file->insn_list && \
@@ -1174,7 +1161,7 @@ static int update_insn_state(struct instruction *insn, struct insn_state *state)
11741161
regs[CFI_BP].base = CFI_BP;
11751162
regs[CFI_BP].offset = -state->stack_size;
11761163
state->bp_scratch = false;
1177-
} else if (!nofp) {
1164+
} else if (!no_fp) {
11781165

11791166
WARN_FUNC("unknown stack-related register move",
11801167
insn->sec, insn->offset);
@@ -1345,7 +1332,7 @@ static int update_insn_state(struct instruction *insn, struct insn_state *state)
13451332
}
13461333

13471334
/* detect when asm code uses rbp as a scratch register */
1348-
if (!nofp && insn->func && op->src.reg == CFI_BP &&
1335+
if (!no_fp && insn->func && op->src.reg == CFI_BP &&
13491336
cfa->base != CFI_BP)
13501337
state->bp_scratch = true;
13511338
break;
@@ -1593,7 +1580,7 @@ static int validate_branch(struct objtool_file *file, struct instruction *first,
15931580

15941581
/* fallthrough */
15951582
case INSN_CALL_DYNAMIC:
1596-
if (!nofp && func && !has_valid_stack_frame(&state)) {
1583+
if (!no_fp && func && !has_valid_stack_frame(&state)) {
15971584
WARN_FUNC("call without frame pointer save/setup",
15981585
sec, insn->offset);
15991586
return 1;
@@ -1779,15 +1766,6 @@ static int validate_reachable_instructions(struct objtool_file *file)
17791766
if (insn->visited || ignore_unreachable_insn(insn))
17801767
continue;
17811768

1782-
/*
1783-
* gcov produces a lot of unreachable instructions. If we get
1784-
* an unreachable warning and the file has gcov enabled, just
1785-
* ignore it, and all other such warnings for the file. Do
1786-
* this here because this is an expensive function.
1787-
*/
1788-
if (gcov_enabled(file))
1789-
return 0;
1790-
17911769
WARN_FUNC("unreachable instruction", insn->sec, insn->offset);
17921770
return 1;
17931771
}
@@ -1812,13 +1790,13 @@ static void cleanup(struct objtool_file *file)
18121790
elf_close(file->elf);
18131791
}
18141792

1815-
int check(const char *_objname, bool _nofp, bool orc)
1793+
int check(const char *_objname, bool _no_fp, bool no_unreachable, bool orc)
18161794
{
18171795
struct objtool_file file;
18181796
int ret, warnings = 0;
18191797

18201798
objname = _objname;
1821-
nofp = _nofp;
1799+
no_fp = _no_fp;
18221800

18231801
file.elf = elf_open(objname, orc ? O_RDWR : O_RDONLY);
18241802
if (!file.elf)
@@ -1829,7 +1807,7 @@ int check(const char *_objname, bool _nofp, bool orc)
18291807
file.whitelist = find_section_by_name(file.elf, ".discard.func_stack_frame_non_standard");
18301808
file.rodata = find_section_by_name(file.elf, ".rodata");
18311809
file.c_file = find_section_by_name(file.elf, ".comment");
1832-
file.ignore_unreachables = false;
1810+
file.ignore_unreachables = no_unreachable;
18331811
file.hints = false;
18341812

18351813
arch_initial_func_cfi_state(&initial_func_cfi);

tools/objtool/check.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ struct objtool_file {
6161
bool ignore_unreachables, c_file, hints;
6262
};
6363

64-
int check(const char *objname, bool nofp, bool orc);
64+
int check(const char *objname, bool no_fp, bool no_unreachable, bool orc);
6565

6666
struct instruction *find_insn(struct objtool_file *file,
6767
struct section *sec, unsigned long offset);

0 commit comments

Comments
 (0)