[PATCH v5 0/6] Add support for LoongArch32
mengqinggang
mengqinggang@loongson.cn
Tue Mar 3 09:54:20 GMT 2026
在 2026/3/2 22:27, Adhemerval Zanella Netto 写道:
>
> On 02/03/26 06:36, mengqinggang wrote:
>> 在 2026/3/2 16:05, mengqinggang 写道:
>>> Add support for LoongArch32(LA32) with ilp32d abi and
>>> LoongArch32 Reduced(LA32R) with ilp32s abi.
>>>
>>> The gcc and binutils master branch have added LA32 support.
>>>
>>> The kernel has added basic LA32 support[6]. But build infrastructures
>>> of LoongArch32 are not enabled yet, because we need to adjust
>>> irqchip drivers and wait for GNU toolchain be upstream first.
>>>
>>> You can build toolchains by script/build-many-glibcs.py:
>>> LA32 ilp32d abi:
>>> build-many-glibcs.py -j128 --keep all . compilers loongarch32-linux-gnu
>>> LA32R ilp32s abi:
>>> build-many-glibcs.py -j128 --keep all . compilers loongarch32-linux-gnusf
>>>
>>> LA32 tested by qemu-user and qemu-system.
>>> Most testcases passed on LA32.
>>> Tested on LA64 with no regression.
>>>
>>> LA32 ilp32d abi:
>>> FAIL: misc/tst-pidfd
>>
>> misc/tst-pidfd fail because pidfd_send_signal return -1 with errno E2BIG.
>> It may be cause by Linux kernel post_copy_siginfo_from_user funcion.
>>
>> 3508 static int post_copy_siginfo_from_user(kernel_siginfo_t *info,
>> 3509 const siginfo_t __user *from)
>> 3510 {
>> 3511 if (unlikely(!known_siginfo_layout(info->si_signo, info->si_code))) {
>> 3512 char __user *expansion = si_expansion(from);
>> 3513 char buf[SI_EXPANSION_SIZE];
>> 3514 int i;
>> 3515 /*
>> 3516 * An unknown si_code might need more than
>> 3517 * sizeof(struct kernel_siginfo) bytes. Verify all of the
>> 3518 * extra bytes are 0. This guarantees copy_siginfo_to_user
>> 3519 * will return this data to userspace exactly.
>> 3520 */
>> 3521 if (copy_from_user(&buf, expansion, SI_EXPANSION_SIZE))
>> 3522 return -EFAULT;
>> 3523 for (i = 0; i < SI_EXPANSION_SIZE; i++) {
>> 3524 if (buf[i] != 0)
>> 3525 return -E2BIG;
>> 3526 }
>> 3527 }
>> 3528 return 0;
>> 3529 }
>>
>> If init siginfo_t to 0, the test can pass.
>>
>> --- a/sysdeps/unix/sysv/linux/tst-pidfd.c
>> +++ b/sysdeps/unix/sysv/linux/tst-pidfd.c
>> @@ -210,13 +210,13 @@ do_test (void)
>> /* Wait for second sigtimedwait. */
>> support_process_state_wait (pid, support_process_state_sleeping);
>> {
>> - siginfo_t info =
>> + siginfo_t info = {0};
>> {
>> - .si_signo = SIGUSR2,
>> - .si_errno = EAGAIN,
>> - .si_code = -10,
>> - .si_pid = ppid,
>> - .si_uid = puid
>> + info.si_signo = SIGUSR2;
>> + info.si_errno = EAGAIN;
>> + info.si_code = -10;
>> + info.si_pid = ppid;
>> + info.si_uid = puid;
>> };
>> TEST_COMPARE (pidfd_send_signal (pidfd, SIGUSR2, &info, 0), 0);
>> }
>>
>> Should it be modified in this way?
> I have sent a similar patch during 2.43 release [1], and we did not have consensus
> if this the correct approach.
>
> [1] https://patchwork.sourceware.org/project/glibc/patch/20260120131337.2574254-1-adhemerval.zanella@linaro.org/
LoongArch64 gcc generates call memset to fully zero-filling the struct.
But LoongArch32 gcc not generate call memset.
Maybe we can fix LoongArch32 gcc to resolve this problem.
76 # t.c:42: siginfo_t info =
77 addi.d $r13,$r22,-160 # tmp96,,
78 addi.w $r12,$r0,128 # 0x80 # tmp97,
79 or $r6,$r12,$r0 #, tmp97
80 or $r5,$r0,$r0 #,
81 or $r4,$r13,$r0 #, tmp96
82 pcaddu18i $r1,%call36(memset) #
83 jirl $r1,$r1,0
84 addi.w $r12,$r0,12 # 0xc # tmp99,
85 st.w $r12,$r22,-160 # tmp99, info.si_signo
86 addi.w $r12,$r0,11 # 0xb # tmp100,
87 st.w $r12,$r22,-156 # tmp100, info.si_errno
88 addi.w $r12,$r0,-10 #
0xfffffffffffffff6 # tmp101,
89 st.w $r12,$r22,-152 # tmp101, info.si_code
90 la.local $r12,ppid # tmp102,
91 ldptr.w $r12,$r12,0 # ppid.0_3, ppid
92 st.w $r12,$r22,-144 # ppid.0_3,
info._sifields._kill.si_pid
93 la.local $r12,puid # tmp103,
94 ldptr.w $r12,$r12,0 # puid.1_4, puid
95 st.w $r12,$r22,-140 # puid.1_4,
info._sifields._kill.si_uid
More information about the Libc-alpha
mailing list