objtool: Handle special cases of dead end insn

There are some "unreachable instruction" objtool warnings when compiling
with Clang on LoongArch, this is because the "break" instruction is set
as dead end due to its type is INSN_BUG in decode_instructions() at the
beginning, and it does not set insn->dead_end of the "break" instruction
as false after checking ".rela.discard.reachable" in add_dead_ends(), so
the next instruction of "break" is marked as unreachable.

Actually, it can find the reachable instruction after parsing the section
".rela.discard.reachable", in some cases, the "break" instruction may not
be the first previous instruction with scheduling by Machine Instruction
Scheduler of LLVM, it should find more times and then set insn->dead_end
of the "break" instruction as false.

This is preparation for later patch on LoongArch, there is no effect for
the other archs with this patch.

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: michael <michael5hzg@gmail.com>
Signed-off-by: maoxiaochuan <maoxiaochuan@loongson.cn>
This commit is contained in:
Tiezhu Yang
2025-02-13 14:26:40 +08:00
committed by maoxiaochuan
parent 15a2bee1ab
commit b30e13e8b8
+16
View File
@@ -22,6 +22,10 @@
#include <linux/static_call_types.h>
#include <linux/string.h>
#ifndef EM_LOONGARCH
#define EM_LOONGARCH 258
#endif
struct alternative {
struct alternative *next;
struct instruction *insn;
@@ -711,6 +715,18 @@ reachable:
}
insn->dead_end = false;
/* Handle the special cases compiled with Clang on LoongArch */
if (file->elf->ehdr.e_machine == EM_LOONGARCH &&
reloc->sym->type == STT_SECTION) {
while (insn && insn_func(insn)) {
insn = prev_insn_same_sym(file, insn);
if (insn && insn->dead_end) {
insn->dead_end = false;
break;
}
}
}
}
return 0;