diff options
Diffstat (limited to 'tools/objtool/builtin-check.c')
-rw-r--r-- | tools/objtool/builtin-check.c | 68 |
1 files changed, 35 insertions, 33 deletions
diff --git a/tools/objtool/builtin-check.c b/tools/objtool/builtin-check.c index 143b6cdd7f06..e8a1f699058a 100644 --- a/tools/objtool/builtin-check.c +++ b/tools/objtool/builtin-check.c | |||
@@ -97,6 +97,19 @@ static struct instruction *next_insn_same_sec(struct objtool_file *file, | |||
97 | return next; | 97 | return next; |
98 | } | 98 | } |
99 | 99 | ||
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 | |||
100 | #define for_each_insn(file, insn) \ | 113 | #define for_each_insn(file, insn) \ |
101 | list_for_each_entry(insn, &file->insn_list, list) | 114 | list_for_each_entry(insn, &file->insn_list, list) |
102 | 115 | ||
@@ -713,6 +726,7 @@ static struct rela *find_switch_table(struct objtool_file *file, | |||
713 | struct instruction *insn) | 726 | struct instruction *insn) |
714 | { | 727 | { |
715 | struct rela *text_rela, *rodata_rela; | 728 | struct rela *text_rela, *rodata_rela; |
729 | struct instruction *orig_insn = insn; | ||
716 | 730 | ||
717 | text_rela = find_rela_by_dest_range(insn->sec, insn->offset, insn->len); | 731 | text_rela = find_rela_by_dest_range(insn->sec, insn->offset, insn->len); |
718 | if (text_rela && text_rela->sym == file->rodata->sym) { | 732 | if (text_rela && text_rela->sym == file->rodata->sym) { |
@@ -733,10 +747,16 @@ static struct rela *find_switch_table(struct objtool_file *file, | |||
733 | 747 | ||
734 | /* case 3 */ | 748 | /* case 3 */ |
735 | func_for_each_insn_continue_reverse(file, func, insn) { | 749 | func_for_each_insn_continue_reverse(file, func, insn) { |
736 | if (insn->type == INSN_JUMP_UNCONDITIONAL || | 750 | if (insn->type == INSN_JUMP_DYNAMIC) |
737 | insn->type == INSN_JUMP_DYNAMIC) | ||
738 | break; | 751 | break; |
739 | 752 | ||
753 | /* allow small jumps within the range */ | ||
754 | if (insn->type == INSN_JUMP_UNCONDITIONAL && | ||
755 | insn->jump_dest && | ||
756 | (insn->jump_dest->offset <= insn->offset || | ||
757 | insn->jump_dest->offset > orig_insn->offset)) | ||
758 | break; | ||
759 | |||
740 | text_rela = find_rela_by_dest_range(insn->sec, insn->offset, | 760 | text_rela = find_rela_by_dest_range(insn->sec, insn->offset, |
741 | insn->len); | 761 | insn->len); |
742 | if (text_rela && text_rela->sym == file->rodata->sym) | 762 | if (text_rela && text_rela->sym == file->rodata->sym) |
@@ -1034,34 +1054,6 @@ static int validate_branch(struct objtool_file *file, | |||
1034 | return 0; | 1054 | return 0; |
1035 | } | 1055 | } |
1036 | 1056 | ||
1037 | static bool is_gcov_insn(struct instruction *insn) | ||
1038 | { | ||
1039 | struct rela *rela; | ||
1040 | struct section *sec; | ||
1041 | struct symbol *sym; | ||
1042 | unsigned long offset; | ||
1043 | |||
1044 | rela = find_rela_by_dest_range(insn->sec, insn->offset, insn->len); | ||
1045 | if (!rela) | ||
1046 | return false; | ||
1047 | |||
1048 | if (rela->sym->type != STT_SECTION) | ||
1049 | return false; | ||
1050 | |||
1051 | sec = rela->sym->sec; | ||
1052 | offset = rela->addend + insn->offset + insn->len - rela->offset; | ||
1053 | |||
1054 | list_for_each_entry(sym, &sec->symbol_list, list) { | ||
1055 | if (sym->type != STT_OBJECT) | ||
1056 | continue; | ||
1057 | |||
1058 | if (offset >= sym->offset && offset < sym->offset + sym->len) | ||
1059 | return (!memcmp(sym->name, "__gcov0.", 8)); | ||
1060 | } | ||
1061 | |||
1062 | return false; | ||
1063 | } | ||
1064 | |||
1065 | static bool is_kasan_insn(struct instruction *insn) | 1057 | static bool is_kasan_insn(struct instruction *insn) |
1066 | { | 1058 | { |
1067 | return (insn->type == INSN_CALL && | 1059 | return (insn->type == INSN_CALL && |
@@ -1083,9 +1075,6 @@ static bool ignore_unreachable_insn(struct symbol *func, | |||
1083 | if (insn->type == INSN_NOP) | 1075 | if (insn->type == INSN_NOP) |
1084 | return true; | 1076 | return true; |
1085 | 1077 | ||
1086 | if (is_gcov_insn(insn)) | ||
1087 | return true; | ||
1088 | |||
1089 | /* | 1078 | /* |
1090 | * Check if this (or a subsequent) instruction is related to | 1079 | * Check if this (or a subsequent) instruction is related to |
1091 | * CONFIG_UBSAN or CONFIG_KASAN. | 1080 | * CONFIG_UBSAN or CONFIG_KASAN. |
@@ -1146,6 +1135,19 @@ static int validate_functions(struct objtool_file *file) | |||
1146 | ignore_unreachable_insn(func, insn)) | 1135 | ignore_unreachable_insn(func, insn)) |
1147 | continue; | 1136 | continue; |
1148 | 1137 | ||
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 | |||
1149 | WARN_FUNC("function has unreachable instruction", insn->sec, insn->offset); | 1151 | WARN_FUNC("function has unreachable instruction", insn->sec, insn->offset); |
1150 | warnings++; | 1152 | warnings++; |
1151 | } | 1153 | } |