objtool: Fix infinite loop in find_jump_table()

Kristen found a hang in objtool when building with -ffunction-sections.

It was caused by evergreen_pcie_gen2_enable.cold() being laid out
immediately before evergreen_pcie_gen2_enable(). Since their "pfunc" is
always the same, find_jump_table() got into an infinite loop because it
didn't recognize the boundary between the two functions.

Fix that with a new prev_insn_same_sym() helper, which doesn't cross
subfunction boundaries.

Reported-by: Kristen Carlson Accardi <kristen@linux.intel.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/378b51c9d9c894dc3294bc460b4b0869e950b7c5.1588110291.git.jpoimboe@redhat.com

authored by Josh Poimboeuf and committed by Peter Zijlstra 1119d265 0e698dfa

Changed files
+13 -2
tools
objtool
+13 -2
tools/objtool/check.c
··· 72 72 return find_insn(file, func->cfunc->sec, func->cfunc->offset); 73 73 } 74 74 75 + static struct instruction *prev_insn_same_sym(struct objtool_file *file, 76 + struct instruction *insn) 77 + { 78 + struct instruction *prev = list_prev_entry(insn, list); 79 + 80 + if (&prev->list != &file->insn_list && prev->func == insn->func) 81 + return prev; 82 + 83 + return NULL; 84 + } 85 + 75 86 #define func_for_each_insn(file, func, insn) \ 76 87 for (insn = find_insn(file, func->sec, func->offset); \ 77 88 insn; \ ··· 1061 1050 * it. 1062 1051 */ 1063 1052 for (; 1064 - &insn->list != &file->insn_list && insn->func && insn->func->pfunc == func; 1065 - insn = insn->first_jump_src ?: list_prev_entry(insn, list)) { 1053 + insn && insn->func && insn->func->pfunc == func; 1054 + insn = insn->first_jump_src ?: prev_insn_same_sym(file, insn)) { 1066 1055 1067 1056 if (insn != orig_insn && insn->type == INSN_JUMP_DYNAMIC) 1068 1057 break;