[PATCH v3 02/10] objtool: Handle special cases of dead end insn

Tiezhu Yang posted 10 patches 4 days, 8 hours ago
There is a newer version of this series
[PATCH v3 02/10] objtool: Handle special cases of dead end insn
Posted by Tiezhu Yang 4 days, 8 hours ago
There are some "unreachable instruction" objtool warnings when compling
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>
---
 tools/objtool/check.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 9601235e908d..6607cd56459b 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -711,6 +711,18 @@ static int add_dead_ends(struct objtool_file *file)
 		}
 
 		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;
-- 
2.42.0
Re: [PATCH v3 02/10] objtool: Handle special cases of dead end insn
Posted by Jinyang He 4 days, 4 hours ago
On 2024-11-19 14:56, Tiezhu Yang wrote:
> There are some "unreachable instruction" objtool warnings when compling
> 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>
> ---
>   tools/objtool/check.c | 12 ++++++++++++
>   1 file changed, 12 insertions(+)
>
> diff --git a/tools/objtool/check.c b/tools/objtool/check.c
> index 9601235e908d..6607cd56459b 100644
> --- a/tools/objtool/check.c
> +++ b/tools/objtool/check.c
> @@ -711,6 +711,18 @@ static int add_dead_ends(struct objtool_file *file)
>   		}
>   
>   		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;
> +				}
> +			}
> +		}
Does it cancel the previous instruction which has insn->dead_end?
Why the previous, and why just for LoongArch?
IMO if we annotate reachable, we should cancel all instructions which
are from the sym head to current insn, not only previous. Otherwise,
why it is previous but not the previous of previous.
>   	}
>   
>   	return 0;