Re: [PATCH v1] objtool/LoongArch: Mark special atomic instruction as INSN_BUG type
From: Tiezhu Yang
Date: Tue Sep 16 2025 - 08:19:06 EST
On 2025/9/16 下午5:02, WANG Rui wrote:
On Tue, Sep 16, 2025 at 2:11 PM Tiezhu Yang <yangtiezhu@xxxxxxxxxxx> wrote:
When compiling with LLVM and CONFIG_RUST is set, there exists the
following objtool warning:
rust/compiler_builtins.o: warning: objtool: __rust__unordsf2(): unexpected end of section .text.unlikely.
objdump shows that the end of section .text.unlikely is a atomic
instruction:
amswap.w $zero, $ra, $zero
According to the LoongArch Reference Manual, if the amswap.w atomic
memory access instruction has the same register number as rd and rj,
the execution will trigger an Instruction Non-defined Exception, so
mark the above instruction as INSN_BUG type to fix the warning.
LLVM lowers `llvm.trap()` to `amswap.w R0, R1, R0`. For x86, it lowers
to `ud2`, and objtool marks it as INSN_BUG.
https://github.com/llvm/llvm-project/blob/788a25a0f71bfa5e5e1c12ad093993b115d10e7a/llvm/lib/Target/LoongArch/LoongArchInstrInfo.td#L1376-L1381
Thanks for the detailed explanation from the point of view of the
compiler.
LLVM and GCC handle this differently, GCC lowers it to a break
instruction. Since the break instruction has other uses, can objtool
mark all break instructions as INSN_BUG? or it should mark different
types based on the break immediate code.
If the break immediate code is 0, it should mark the type
as INSN_TRAP. If the break immediate code is 1, it should
mark the type as INSN_BUG. I will do it.
Thanks,
Tiezhu