On Thu, 2025-09-25 at 11:17 +0800, Huacai Chen wrote:
> Hi, Ruoyao,
> 
> On Tue, Sep 23, 2025 at 8:34 PM Xi Ruoyao <[email protected]> wrote:
> > 
> > In some applications (notably the Linux kernel), "break 0" is used as a
> > trap that a handler may be able to recover.  But in GCC the "trap"
> > pattern is meant to make the program rightfully die instead.
> > 
> > As [1] describes, sometimes it's vital to distinguish between the two
> > cases.
> > 
> > Use the "documented illegal instruction" amswap.w $r0,$r1,$r0 for "trap"
> > instead.  This also aligns the behavior with x86_64 GCC and LoongArch
> > clang.
> Can we use "break 1" instead?

AFAIK the break codes are allocated nowhere except in a Linux header so
I don't want to use it in compiler which may target some different
operating system.

I also want to align the behavior between GCC and Clang.  Thus if we
want to use "break 1" we should document the allocation somewhere and
also switch Clang to use it.

And if "break 1" is invoked in user-space, the kernel still delivers a
SIGTRAP, but IMO it's better to have SIGILL here like x86 ud2 (as
SIGTRAP is "trace/breakpoint trap" that the program can more likely use
as something catchable, but when the compiler generates the "trap"
instruction it wants the program to just die here).

-- 
Xi Ruoyao <[email protected]>

Reply via email to