[PATCH 2/2] aarch64: Set the syscall register right before doing the syscall.

Adhemerval Zanella Netto adhemerval.zanella@linaro.org
Tue Apr 11 14:15:28 GMT 2023



On 11/04/23 10:50, Florian Weimer via Libc-alpha wrote:
> * Joe Simmons-Talbott via Libc-alpha:
> 
>>    ({ long _sys_result;						\
>>       {								\
>>         LOAD_ARGS_##nr (args)					\
>>         register long _x8 asm ("x8") = (name);			\
>> +       if (__builtin_constant_p(name))				\
>> +         asm volatile ("mov	x8, " MSTR(name) ";"		\
>> +                       : /* no output */ : "i" (name) : "x8");	\
>>         asm volatile ("svc	0	// syscall " # name     \
>>  		     : "=r" (_x0) : "r"(_x8) ASM_ARGS_##nr : "memory");	\
>>         _sys_result = _x0;					\
> 
> I think you should do this in a single assembler statement, load the
> constant only once.

Is this required because compiler is free to reorganize the argument
list? I think it should me it clear on the commit message.

Using a single assembler would require two inline asm, something like:

diff --git a/sysdeps/unix/sysv/linux/aarch64/sysdep.h b/sysdeps/unix/sysv/linux/aarch64/sysdep.h                                                                                            index e94d1703ad..2a128bb72d 100644                                                                                                                                                         --- a/sysdeps/unix/sysv/linux/aarch64/sysdep.h                                                                                                                                              +++ b/sysdeps/unix/sysv/linux/aarch64/sysdep.h                                                                                                                                              @@ -172,9 +172,19 @@
   ({ long _sys_result;                                         \
      {                                                         \
        LOAD_ARGS_##nr (args)                                   \
-       register long _x8 asm ("x8") = (name);                  \
-       asm volatile ("svc      0       // syscall " # name     \
-                    : "=r" (_x0) : "r"(_x8) ASM_ARGS_##nr : "memory"); \
+       if (__builtin_constant_p (name))                                \
+        asm volatile ("mov     x8, %1\n"                       \
+                      "svc     0       // syscall " # name     \
+                      : "=r" (_x0)                             \
+                      : "i" (name) ASM_ARGS_##nr               \
+                      : "x8", "memory");                       \
+       else                                                    \
+         {                                                     \
+          register long _x8 asm ("x8") = (name);               \
+          asm volatile ("svc      0       // syscall " # name  \
+                        : "=r" (_x0)                           \
+                        : "r"(_x8) ASM_ARGS_##nr : "memory");  \
+        }                                                      \
        _sys_result = _x0;                                      \
      }                                                         \
      _sys_result; })

Which really makes me doubt if this extra complexity is really necessary...



More information about the Libc-alpha mailing list