aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorJosh Poimboeuf <jpoimboe@redhat.com>2017-07-24 19:34:14 -0400
committerIngo Molnar <mingo@kernel.org>2017-07-25 05:12:45 -0400
commit867ac9d737094e46a6c33213f16dd1ec9e8bd5d5 (patch)
tree708c868a63e86271f0572ea7120a406bfe7e88a1 /tools
parent9683a64fc3cb67e663859a6bb2e0db5dcee9ed32 (diff)
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: 9cfffb116887 ("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>
Diffstat (limited to 'tools')
-rw-r--r--tools/objtool/builtin-check.c7
-rw-r--r--tools/objtool/builtin-orc.c4
-rw-r--r--tools/objtool/check.c36
-rw-r--r--tools/objtool/check.h2
4 files changed, 14 insertions, 35 deletions
diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c
index eedf089b1495..57254f5b2779 100644
--- a/tools/objtool/builtin-check.c
+++ b/tools/objtool/builtin-check.c
@@ -29,7 +29,7 @@
29#include "builtin.h" 29#include "builtin.h"
30#include "check.h" 30#include "check.h"
31 31
32bool nofp; 32bool no_fp, no_unreachable;
33 33
34static const char * const check_usage[] = { 34static const char * const check_usage[] = {
35 "objtool check [<options>] file.o", 35 "objtool check [<options>] file.o",
@@ -37,7 +37,8 @@ static const char * const check_usage[] = {
37}; 37};
38 38
39const struct option check_options[] = { 39const 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"),
41 OPT_END(), 42 OPT_END(),
42}; 43};
43 44
@@ -52,5 +53,5 @@ int cmd_check(int argc, const char **argv)
52 53
53 objname = argv[0]; 54 objname = argv[0];
54 55
55 return check(objname, nofp, false); 56 return check(objname, no_fp, no_unreachable, false);
56} 57}
diff --git a/tools/objtool/builtin-orc.c b/tools/objtool/builtin-orc.c
index 5ca41ab0df48..4c6b5c9ef073 100644
--- a/tools/objtool/builtin-orc.c
+++ b/tools/objtool/builtin-orc.c
@@ -37,7 +37,7 @@ static const char *orc_usage[] = {
37}; 37};
38 38
39extern const struct option check_options[]; 39extern const struct option check_options[];
40extern bool nofp; 40extern bool no_fp, no_unreachable;
41 41
42int cmd_orc(int argc, const char **argv) 42int cmd_orc(int argc, const char **argv)
43{ 43{
@@ -51,7 +51,7 @@ int cmd_orc(int argc, const char **argv)
51 51
52 objname = argv[0]; 52 objname = argv[0];
53 53
54 return check(objname, nofp, true); 54 return check(objname, no_fp, no_unreachable, true);
55 55
56 } 56 }
57 57
diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 368275de5f23..3436a942b606 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -33,7 +33,7 @@ struct alternative {
33}; 33};
34 34
35const char *objname; 35const char *objname;
36static bool nofp; 36static bool no_fp;
37struct cfi_state initial_func_cfi; 37struct cfi_state initial_func_cfi;
38 38
39struct instruction *find_insn(struct objtool_file *file, 39struct instruction *find_insn(struct objtool_file *file,
@@ -59,19 +59,6 @@ static struct instruction *next_insn_same_sec(struct objtool_file *file,
59 return next; 59 return next;
60} 60}
61 61
62static 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
75#define func_for_each_insn(file, func, insn) \ 62#define func_for_each_insn(file, func, insn) \
76 for (insn = find_insn(file, func->sec, func->offset); \ 63 for (insn = find_insn(file, func->sec, func->offset); \
77 insn && &insn->list != &file->insn_list && \ 64 insn && &insn->list != &file->insn_list && \
@@ -1174,7 +1161,7 @@ static int update_insn_state(struct instruction *insn, struct insn_state *state)
1174 regs[CFI_BP].base = CFI_BP; 1161 regs[CFI_BP].base = CFI_BP;
1175 regs[CFI_BP].offset = -state->stack_size; 1162 regs[CFI_BP].offset = -state->stack_size;
1176 state->bp_scratch = false; 1163 state->bp_scratch = false;
1177 } else if (!nofp) { 1164 } else if (!no_fp) {
1178 1165
1179 WARN_FUNC("unknown stack-related register move", 1166 WARN_FUNC("unknown stack-related register move",
1180 insn->sec, insn->offset); 1167 insn->sec, insn->offset);
@@ -1345,7 +1332,7 @@ static int update_insn_state(struct instruction *insn, struct insn_state *state)
1345 } 1332 }
1346 1333
1347 /* detect when asm code uses rbp as a scratch register */ 1334 /* 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 &&
1349 cfa->base != CFI_BP) 1336 cfa->base != CFI_BP)
1350 state->bp_scratch = true; 1337 state->bp_scratch = true;
1351 break; 1338 break;
@@ -1593,7 +1580,7 @@ static int validate_branch(struct objtool_file *file, struct instruction *first,
1593 1580
1594 /* fallthrough */ 1581 /* fallthrough */
1595 case INSN_CALL_DYNAMIC: 1582 case INSN_CALL_DYNAMIC:
1596 if (!nofp && func && !has_valid_stack_frame(&state)) { 1583 if (!no_fp && func && !has_valid_stack_frame(&state)) {
1597 WARN_FUNC("call without frame pointer save/setup", 1584 WARN_FUNC("call without frame pointer save/setup",
1598 sec, insn->offset); 1585 sec, insn->offset);
1599 return 1; 1586 return 1;
@@ -1779,15 +1766,6 @@ static int validate_reachable_instructions(struct objtool_file *file)
1779 if (insn->visited || ignore_unreachable_insn(insn)) 1766 if (insn->visited || ignore_unreachable_insn(insn))
1780 continue; 1767 continue;
1781 1768
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
1791 WARN_FUNC("unreachable instruction", insn->sec, insn->offset); 1769 WARN_FUNC("unreachable instruction", insn->sec, insn->offset);
1792 return 1; 1770 return 1;
1793 } 1771 }
@@ -1812,13 +1790,13 @@ static void cleanup(struct objtool_file *file)
1812 elf_close(file->elf); 1790 elf_close(file->elf);
1813} 1791}
1814 1792
1815int check(const char *_objname, bool _nofp, bool orc) 1793int check(const char *_objname, bool _no_fp, bool no_unreachable, bool orc)
1816{ 1794{
1817 struct objtool_file file; 1795 struct objtool_file file;
1818 int ret, warnings = 0; 1796 int ret, warnings = 0;
1819 1797
1820 objname = _objname; 1798 objname = _objname;
1821 nofp = _nofp; 1799 no_fp = _no_fp;
1822 1800
1823 file.elf = elf_open(objname, orc ? O_RDWR : O_RDONLY); 1801 file.elf = elf_open(objname, orc ? O_RDWR : O_RDONLY);
1824 if (!file.elf) 1802 if (!file.elf)
@@ -1829,7 +1807,7 @@ int check(const char *_objname, bool _nofp, bool orc)
1829 file.whitelist = find_section_by_name(file.elf, ".discard.func_stack_frame_non_standard"); 1807 file.whitelist = find_section_by_name(file.elf, ".discard.func_stack_frame_non_standard");
1830 file.rodata = find_section_by_name(file.elf, ".rodata"); 1808 file.rodata = find_section_by_name(file.elf, ".rodata");
1831 file.c_file = find_section_by_name(file.elf, ".comment"); 1809 file.c_file = find_section_by_name(file.elf, ".comment");
1832 file.ignore_unreachables = false; 1810 file.ignore_unreachables = no_unreachable;
1833 file.hints = false; 1811 file.hints = false;
1834 1812
1835 arch_initial_func_cfi_state(&initial_func_cfi); 1813 arch_initial_func_cfi_state(&initial_func_cfi);
diff --git a/tools/objtool/check.h b/tools/objtool/check.h
index ac3d4b13f17b..c9af11f0c8af 100644
--- a/tools/objtool/check.h
+++ b/tools/objtool/check.h
@@ -61,7 +61,7 @@ struct objtool_file {
61 bool ignore_unreachables, c_file, hints; 61 bool ignore_unreachables, c_file, hints;
62}; 62};
63 63
64int check(const char *objname, bool nofp, bool orc); 64int check(const char *objname, bool no_fp, bool no_unreachable, bool orc);
65 65
66struct instruction *find_insn(struct objtool_file *file, 66struct instruction *find_insn(struct objtool_file *file,
67 struct section *sec, unsigned long offset); 67 struct section *sec, unsigned long offset);