[PATCH v5 0/6] Add support for LoongArch32

mengqinggang mengqinggang@loongson.cn
Wed Mar 11 02:20:01 GMT 2026


Ping.
Or just apply this patch?
https://patchwork.sourceware.org/project/glibc/patch/20260120131337.2574254-1-adhemerval.zanella@linaro.org/

在 2026/3/4 16:41, mengqinggang 写道:
>
> 在 2026/3/4 14:46, mengqinggang 写道:
>>
>> 在 2026/3/4 09:52, mengqinggang 写道:
>>>
>>> 在 2026/3/4 00:33, Xi Ruoyao 写道:
>>>> On Tue, 2026-03-03 at 19:28 +0800, mengqinggang wrote:
>>>>> 在 2026/3/3 18:11, Xi Ruoyao 写道:
>>>>>> On Tue, 2026-03-03 at 17:54 +0800, mengqinggang wrote:
>>>>>>> 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.
>>>>>> This is not a compiler bug so there's nothing to be fixed in the
>>>>>> compiler.  In C using = {...} to initialize a struct with automatic
>>>>>> storage duration will leave the padding bits unspecified, unless the
>>>>>> initializer is empty.
>>>>>>
>>>>>> See https://gcc.gnu.org/PR104607 which has been resolved as invalid
>>>>>> years ago.
>>>>> According to what you said, loongarch64 gcc should not generate call
>>>>> memset assembly code?
>>>> I don't think it should.  This seems a missed-optimization on 
>>>> almost all
>>>> GCC ports (GCC r16-7721 actually emits the memset for LA32...)
>>>>
>>> Only loongarch64 gcc generate call memset for the following code.
>>>
>>>   1 #include <errno.h>
>>>   2 #include <fcntl.h>
>>>   3 #include <limits.h>
>>>   4 #include <sys/pidfd.h>
>>>   5 #include <sys/wait.h>
>>>   6 #include <stdlib.h>
>>>   7 #include <stdio.h>
>>>   8 #include <unistd.h>
>>>   9
>>>  10 static pid_t ppid;
>>>  11 static uid_t puid;
>>>  12
>>>  13 int
>>>  14 main (void)
>>>  15 {
>>>  16   ppid = getpid ();
>>>  17   puid = getuid ();
>>>  18   pid_t pid = fork ();
>>>  19   if (pid != 0)
>>>  20   {
>>>  21     int pidfd = pidfd_open (pid, 0);
>>>  22     printf("pidfd %d\n", pidfd);
>>>  23     {
>>>  24       siginfo_t info =
>>>  25         {
>>>  26           .si_signo = SIGUSR2,
>>>  27           .si_errno = EAGAIN,
>>>  28           .si_code = -10,
>>>  29           .si_pid = ppid,
>>>  30           .si_uid = puid
>>>  31         };
>>>  32       int r = pidfd_send_signal (pidfd, SIGUSR2, &info, 0);
>>>  33       printf("pidfd r = %d\n", r);
>>>  34     }
>>>  35   }
>>>  36   return 0;
>>>  37 }
>>>
>> If wordsize is 64, there is an int __pad0.
>> Maybe this difference causes the loongarch64 gcc to generate call 
>> memset,
>> while the loongarch32 gcc does not.
>
>
> On 32 bit target, gcc believes all fields have been initialized. So 
> gcc dose not generate call memset.
> Currently, I think  add a memset call in source code is a good idea.
>
>
>>
>> sysdeps/unix/sysv/linux/bits/types/siginfo_t.h:
>>
>>  36 typedef struct
>>  37   {
>>  38     int si_signo;               /* Signal number.  */
>>  39 #if __SI_ERRNO_THEN_CODE
>>  40     int si_errno;               /* If non-zero, an errno value 
>> associated with
>>  41                                    this signal, as defined in 
>> <errno.h>.  */
>>  42     int si_code;                /* Signal code.  */
>>  43 #else
>>  44     int si_code;
>>  45     int si_errno;
>>  46 #endif
>>  47 #if __WORDSIZE == 64
>>  48     int __pad0;                 /* Explicit padding.  */
>>  49 #endif
>>  50
>>  51     union
>>  52       {
>>  53         int _pad[__SI_PAD_SIZE];
>>  54
>>  55          /* kill().  */
>>  56         struct
>>  57           {
>>  58             __pid_t si_pid;     /* Sending process ID.  */
>>  59             __uid_t si_uid;     /* Real user ID of sending 
>> process.  */
>>  60           } _kill;
>>



More information about the Libc-alpha mailing list