Re: [PATCH] fix: support LoongArch64 in my-syscalls.S to resolve step-over-thread-exit-while-stop-all-threads.exp build failure

Tiezhu Yang
2025-10-22T08:49:44Z

On 2025/10/22 上午3:30, Coder_Y wrote:
> This patch adds syscall wrappers for LoongArch64 to gdb/testsuite/lib/my-syscalls.S.

It is better to change the patch title to:
gdb/testsuite: Add LoongArch case in my-syscalls.S

> - Implements the missing `__loongarch64` section
> - Uses `lu12i.w` + `ori` to load the syscall number into `$a7`

Why not using the instruction "li.w" directly?

> - Triggers system calls via `syscall 0`
> - Returns to caller using `jr $ra`

You can use the instruction "ret" to make it more readable.
please see opcodes/loongarch-opc.c file to get more info.

> This change fixes build failures in LoongArch64 when running:
> gdb.threads/step-over-thread-exit-while-stop-all-threads.exp
>
> Tested on: loongarch64-unknown-linux-gnu
> Result: expected testcases passed

Did you meet any real problems when debugging?
If yes, please describe it in the commit message.

> Signed-off-by: Nick Young <zewyang@foxmail.com>

Please use your real name here and make it consistent with 'From'
instead of abbreviation.

> ---
> gdb/testsuite/lib/my-syscalls.S | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
>
> diff --git a/gdb/testsuite/lib/my-syscalls.S b/gdb/testsuite/lib/my-syscalls.S
> index c514b32d..a8862b5c 100644
> --- a/gdb/testsuite/lib/my-syscalls.S
> +++ b/gdb/testsuite/lib/my-syscalls.S
> @@ -63,6 +63,19 @@ NAME: ;\
> NAME ## _syscall: ;\
> svc #0
>
> +#elif defined(__loongarch64)
> +
> +/* LoongArch 64-bit syscall wrapper */
> +#define SYSCALL(NAME, NR) \
> +.global NAME ;\
> +NAME: ;\
> + lu12i.w $a7, NR >> 12 ;\
> + ori $a7, $a7, NR & 0xfff ;\
> + /* syscall number */ \
> +NAME ## _syscall: ;\
> + syscall 0 ;\
> + jr $ra
> +
> #else
> # error "Unsupported architecture"
> #endif

Thanks,
Tiezhu